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
| Need | Command |
|---|---|
| Keep a database running for the job | docker compose up -d db |
| Run the test suite once and exit | docker compose run --rm tests |
| Block until deps are healthy | docker compose up -d --wait |
| One-off migration or seed | docker 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 testGotchas
docker compose rundoes not publish the service ports by default; add--service-portsif you need them.--rmremoves the one-off container after it exits so leftover containers do not pile up across jobs.
Related guides
How to Run Integration Tests Against Compose Services in CIBoot a real backend with docker compose in CI, wait for it to be healthy, run your integration suite against…
How to Run docker compose up and Wait for Healthy Services in CIStart a Compose stack in CI with docker compose up -d and block until every service is healthy using the --wa…
How to Build Images With Compose in a CI PipelineBuild all service images defined in docker-compose.yml in one step with docker compose build, pin the build c…