---
title: "Docker Compose \"Bind for 0.0.0.0:5432 failed: port is already allocated\""
canonical: "https://techwiki.co.uk/virtualization/docker-compose-port-is-already-allocated"
author: "Adam Birds"
article_type: "documentation"
published: "2026-10-24T01:07:15.045Z"
updated: "2026-10-24T01:07:15.045Z"
categories: ["Virtualization"]
tags: ["docker","docker-compose"]
---**If `docker compose up` fails to start a container because another project or container is already using the same host port, the container is created but never starts:**

```text
Error response from daemon: failed to set up container networking: driver failed programming external connectivity on endpoint <project>-db-1 (<endpoint-id>): Bind for 0.0.0.0:5432 failed: port is already allocated
```

This is common when running two projects side by side that both publish a database (`5432`), Redis (`6379`) or a web server (`80`/`8000`) on the host.

## Cause

The service has a `ports:` entry such as `"5432:5432"`, which binds the container port to the same port on the host. Only one process can hold a host port, so the second project's container cannot start.

Often the published port is not needed at all: other services in the same Compose project reach the database over the internal network by service name (for example `db:5432`), not through the host.

## Fix

Leave the original `docker-compose.yml` untouched and add an override file. This is useful when the Compose file belongs to someone else or is shared with a team.

Create an override file, for example `compose.no-ports.yml`:

```yaml
services:
    db:
        ports: !reset []
```

Then start the project with both files:

```bash
docker compose -f docker-compose.yml -f compose.no-ports.yml up -d
```

The `db` service now publishes nothing on the host, and other containers in the project still reach it at `db:5432`.

### If the port is still needed from the host

Publish it on a free host port instead, using `!override` to **replace** the list:

```yaml
services:
    db:
        ports: !override
            - "5433:5432"
```

Then connect from the host on `localhost:5433`.

## Verify

```bash
docker compose -f docker-compose.yml -f compose.no-ports.yml ps
```

Every service should show as `running`. To see what currently holds the conflicting host port:

```bash
docker ps --filter "publish=5432"
# or, for processes outside Docker
sudo lsof -iTCP:5432 -sTCP:LISTEN
```

## Notes

- **Plain overrides do not work for ports.** Compose merges `ports` from multiple files by **appending**, so an override containing `ports: ["5433:5432"]` keeps the original `5432:5432` as well and still fails. `!reset` (clear the list) and `!override` (replace the list) are what make the override take effect.
- `!reset` and `!override` need Docker Compose v2.24.0 or later. Check with `docker compose version`.
- The same approach works for `volumes`, `environment` and other list or map fields that Compose merges rather than replaces.
- Alternatively, stop the other project with `docker compose -p <other-project> down`, but that is not an option if both need to run at once.
