How to Choose Compose vs GitHub Actions Services
The services block is simplest for one or two backends, while Compose wins when you want the same multi-service stack locally and in CI.
Use the Actions services: block for a lone database. Reach for Compose when you have several interdependent services, custom build contexts, or want CI to match docker compose up on a laptop.
Comparison
| Factor | services block | docker compose |
|---|---|---|
| Multi-service stacks | Verbose | Native |
| Local parity | None | Same file locally |
| Custom build context | No | Yes via build: |
| Startup ordering | Manual | depends_on + healthy |
Compose approach
.github/workflows/ci.yml
steps:
- uses: actions/checkout@v4
- run: docker compose up -d --wait
- run: npm testGotchas
- With the services block the job reaches the DB on
localhost; with Compose the runner reaches it on the mapped host port. - If your team already runs
docker compose uplocally, using Compose in CI removes a whole class of "works on my machine" gaps.
Related guides
How to Network the Test Runner and Compose Services in CIConnect a CI test runner to Compose services correctly by choosing service-name networking inside the stack o…
How to Provide a Postgres Fixture With Compose in CIStand up a disposable Postgres for CI tests with docker compose, seed it via an init script, and gate the tes…
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…