Skip to content
Latchkey

How to Choose docker compose run vs up in CI

up starts and keeps services running in the background; run executes a single command in a new one-off container and returns its exit code.

Start your databases and queues with docker compose up -d, then use docker compose run --rm <service> <cmd> to run the test command so CI gets that command's exit code directly.

When to use each

NeedCommand
Keep a database running for the jobdocker compose up -d db
Run the test suite once and exitdocker compose run --rm tests
Block until deps are healthydocker compose up -d --wait
One-off migration or seeddocker compose run --rm app npm run migrate

CI step

.github/workflows/ci.yml
steps:
  - run: docker compose up -d --wait db redis
  - run: docker compose run --rm --no-deps tests npm test

Gotchas

  • docker compose run does not publish the service ports by default; add --service-ports if you need them.
  • --rm removes the one-off container after it exits so leftover containers do not pile up across jobs.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →