Skip to content
Latchkey

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

Compose could not publish a service’s port because the host port is already taken. A previous container, a parallel job, or another process on the runner is already bound to it.

What this error means

A docker compose up fails to start a service with Bind for 0.0.0.0:5432 failed: port is already allocated. It often appears on a re-run or on a shared runner where a prior compose stack was not torn down.

docker compose output
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 previous compose stack was not brought down

An earlier compose up (failed job, missing down) left a container still publishing the port on a reused runner.

A parallel job uses the same fixed host port

Two jobs on the same runner both publish 5432:5432; only one can hold the host port at a time.

A host service already binds the port

A Postgres/Redis installed on the runner itself occupies the port the compose service tries to publish.

How to fix it

Tear down the previous stack and free the port

Bring the stack down (removing containers) before starting again.

Terminal
docker compose down --remove-orphans
ss -ltnp | grep ':5432'   # confirm nothing else holds it
docker compose up -d

Use an ephemeral or random host port

Avoid fixed host ports that collide; let Docker assign one, or omit the host side.

docker-compose.yml
services:
  db:
    ports:
      - "5432"        # random host port -> container 5432 (no collision)

How to prevent it

  • Always docker compose down (with cleanup) at the end of a job.
  • Avoid hardcoded host ports that other jobs on the runner may use.
  • Rely on the compose network for inter-service traffic instead of publishing ports.

Frequently asked questions

What causes ""port is already allocated""?
An earlier compose up (failed job, missing down) left a container still publishing the port on a reused runner.
How do I fix "port is already allocated"?
Bring the stack down (removing containers) before starting again.

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card