← Recipes

阅读中文版本

Run E2E Tests Against docker compose

Spin up the full stack with docker compose in CI, wait for readiness, run E2E tests, and tear everything down deterministically.

~40 mintestingdockere2e

Task

Orchestrate a reproducible E2E run against a compose stack inside CI.

When to use this

E2E tests run against a shared staging environment, so failures are hard to reproduce locally.

Prerequisites

  • docker compose
  • An E2E runner such as Playwright
  • Health endpoints for dependencies

Steps

1. Start the stack and wait for health.

docker compose up -d --wait
# or poll a readiness endpoint
for i in $(seq 1 30); do curl -fsS http://localhost:8080/health && break; sleep 2; done

Expected output: The stack is ready before tests start, avoiding race failures.

2. Run tests then always tear down.

npx playwright test || status=$?
docker compose down -v
[ -n "$status" ] && exit $status

Expected output: Tests run against a clean stack and containers are removed even on failure.

Troubleshooting

Problem

Port conflicts on CI

Solution

Randomise host ports or use isolated networks per job.

Problem

Leftover volumes cause stale state

Solution

Always bring the stack down with -v to drop data volumes.

Limitations

  • Compose differs from production orchestration.
  • Startup time adds to CI duration.
  • Not suitable for large multi-node topologies.

What this recipe does

Orchestrate a reproducible E2E run against a compose stack inside CI.

E2E tests run against a shared staging environment, so failures are hard to reproduce locally.

Prerequisites

  • docker compose
  • An E2E runner such as Playwright
  • Health endpoints for dependencies

Procedure

  1. Start the stack and wait for health.
docker compose up -d --wait
# or poll a readiness endpoint
for i in $(seq 1 30); do curl -fsS http://localhost:8080/health && break; sleep 2; done

Expected result: The stack is ready before tests start, avoiding race failures.

  1. Run tests then always tear down.
npx playwright test || status=$?
docker compose down -v
[ -n "$status" ] && exit $status

Expected result: Tests run against a clean stack and containers are removed even on failure.

How to confirm it worked

Run the commands above and confirm every expected result in order. If a step does not produce the stated output, use the troubleshooting notes before continuing. A passing run shows the E2E suite runs against a freshly started stack and the environment is fully removed afterwards.

Troubleshooting

Port conflicts on CI — Randomise host ports or use isolated networks per job.

Leftover volumes cause stale state — Always bring the stack down with -v to drop data volumes.

Limitations

  • Compose differs from production orchestration.
  • Startup time adds to CI duration.
  • Not suitable for large multi-node topologies.