Skip to content
Latchkey

Compose "Bind for 0.0.0.0:PORT failed: port is already allocated" in CI

Compose tried to publish a service port to the host but the host port is already bound, by a leftover container from a prior job, another compose stack, or a service the runner already runs. The bind fails and the service does not start.

What this error means

A docker compose up fails with "Error response from daemon: driver failed programming external connectivity ... Bind for 0.0.0.0:<port> failed: port is already allocated".

compose
Error response from daemon: driver failed programming external connectivity on
endpoint app_db_1: Bind for 0.0.0.0:5432 failed: port is already allocated

Common causes

A leftover container still holds the port

A previous job did not tear down its stack, so an old container is still bound to the host port.

Another process or stack uses the same host port

A second compose project or a runner service maps the same port, so the second bind is refused.

How to fix it

Tear down old stacks before starting

  1. Run docker compose down (with --remove-orphans) before up.
  2. Use a unique project name per job so stacks do not collide.
  3. Re-run; the port is now free to bind.
Terminal
docker compose down --remove-orphans
docker compose up -d

Let the host port be assigned dynamically

In CI you rarely need a fixed host port; publish to an ephemeral host port to avoid collisions.

docker-compose.yml
services:
  db:
    ports:
      - "5432"   # host port chosen automatically

How to prevent it

  • Always docker compose down at job start or end.
  • Use unique project names so stacks do not clash.
  • Avoid pinning host ports in CI; let Docker assign them.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →