Docker: Error response from daemon — port is already allocated

Quick answer

The host port in your -p HOST:CONTAINER mapping is already taken — by another container, a leftover stopped container, or a host process. Find it with docker ps (then lsof -i :PORT), and either stop the conflicting container/process, change the host port (-p 8081:8080), or run docker compose down to clean up.

The exact error string

docker: Error response from daemon: driver failed programming external
connectivity on endpoint web:
Bind for 0.0.0.0:8080 failed: port is already allocated.

# docker compose:
# Error response from daemon: ... Bind for 0.0.0.0:8080 failed: port is already allocated

A host port can be bound by only one thing at a time. Docker tried to bind 8080 on the host for your container, but something already holds it.

Step 1: find what holds the port

Check Docker first — the usual culprit is another container still mapping that port:

docker ps              # look at the PORTS column for 8080
docker ps -a           # include stopped containers still holding the mapping

# not a container? a host process has it:
lsof -i :8080                       # macOS / Linux
netstat -ano | findstr :8080       # Windows (note the PID)

Fix 1: stop the conflicting container

If another container owns the port, stop (and optionally remove) it:

docker stop <container-id-or-name>
docker rm   <container-id-or-name>   # if it's a stale/old one

# bring down a whole compose stack cleanly:
docker compose down

Fix 2: change the host port

If you actually want both things running, map your container to a different host port. Change the left side of the mapping (host), not the right (container):

# host 8081 -> container 8080  (app inside is unchanged)
docker run -p 8081:8080 myimage

# docker-compose.yml
services:
  web:
    ports:
      - "8081:8080"

Fix 3: a non-Docker process holds it

If lsof/netstat shows a regular process (a local dev server, another app) on the port, stop that process or change its port. On the host this is the same conflict Node reports as EADDRINUSE — the OS allows only one listener per port.

# macOS / Linux: kill the PID lsof reported
kill -9 <pid>

# Windows: taskkill with the PID from netstat
taskkill /PID <pid> /F

Debugging checklist

Frequently Asked Questions

What does 'port is already allocated' mean in Docker?

The host port in your -p HOST:CONTAINER mapping is already bound by something else — usually another running container, a leftover container, or a non-Docker process on the host. Only one process can listen on a host port, so Docker can't start the new container.

How do I find what is using the port?

Check Docker first: docker ps shows each container's PORTS column. If nothing there matches, a host process holds it — find it with lsof -i :8080 (macOS/Linux) or netstat -ano | findstr :8080 (Windows). Then stop that container or process, or pick a different host port.

How do I change the host port?

Edit the left side of the -p mapping (host port), not the right (container port). docker run -p 8081:8080 maps host 8081 to the container's 8080. In docker-compose.yml use ports: ['8081:8080']. The app inside the container is unchanged; only the host port differs.

Why does it happen after a crash or Ctrl+C?

A container that didn't shut down cleanly can keep the port reserved. docker ps -a shows stopped containers still holding the mapping. Remove them with docker rm, or run docker compose down to stop and remove the whole stack before starting it again.

How is this different from EADDRINUSE?

It is the Docker-level version of the same problem. EADDRINUSE is what a Node.js process prints when it can't bind a port; 'port is already allocated' is what the Docker daemon prints when it can't bind a host port for a container. Both mean the port is taken — free it or use another.

Can two containers share the same host port?

No. Each host port maps to exactly one container. To run several similar containers, map each to a different host port (8081, 8082, ...), or put them behind a reverse proxy / load balancer that listens on one host port and routes to the containers internally.

More backend & build errors

Browse the full reference for Node.js, Python, Docker, and database errors — exact message, cause, and fix.

All Error References Node: EADDRINUSE Docker: exec format error
About the author

Pasindu Ishan is a software developer based in Sri Lanka. He builds privacy-first developer tools at JSON Dev Tools.