How to Run Integration Tests with Docker Compose in GitHub Actions
Docker Compose brings up your full stack (app, database, queue) so integration tests hit real dependencies.
Run docker compose up -d, wait for services to report healthy, run the tests against the running stack, and tear it down. Compose handles networking between services by name.
Steps
- Run
docker compose up -d --waitso the step blocks until services are healthy. - Run the integration test command against the running stack.
- Always run
docker compose down -vto clean up, even on failure.
Workflow
.github/workflows/ci.yml
jobs:
integration:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: docker compose up -d --wait
- run: npm ci && npm run test:integration
- name: Tear down
if: always()
run: docker compose down -vGotchas
--waitneedshealthcheckdefined on each service, or it returns before they are ready.- Use
down -vto drop volumes so the next run starts from a clean state.
Related guides
How to Run a Test Database as a Service Container with GitHub ActionsSpin up Postgres as a GitHub Actions service container with a health check and port mapping, so your tests co…
How to Seed a Test Database Before Tests with GitHub ActionsRun migrations and seed fixtures into a GitHub Actions service-container database before the test job runs, s…