| title | Docker Port Is Already Allocated | |||||
|---|---|---|---|---|---|---|
| slug | docker-port-is-already-allocated | |||||
| technologies |
|
|||||
| severity | medium | |||||
| tags |
|
|||||
| related |
|
|||||
| last_reviewed | 2026-06-27 |
docker: Error response from daemon: driver failed programming external connectivity on endpoint web (abc123...): Bind for 0.0.0.0:8080 failed: port is already allocated.
Error starting userland proxy: listen tcp4 0.0.0.0:8080: bind: address already in use
When you publish a port with -p host:container, Docker asks the host kernel to
bind the host-side port for its proxy/NAT rules. If another process — another
container, a leftover docker-proxy, or an unrelated host service — already holds
that port, the bind fails and the daemon refuses to start the container. The port
is a host-wide resource; only one listener can own a given address:port at a time.
- docker (libnetwork,
docker-proxy, host networking stack)
medium — the affected container won't start, but the rest of Docker and the host are unaffected. It's typically a fast-to-fix conflict rather than an outage.
- Another running container already publishes the same host port.
- A non-Docker host service (nginx, a dev server, another DB) holds the port.
- A previous container exited uncleanly, leaving a stale
docker-proxybound. - Two services in the same Compose file map to the same host port.
- The port is in the ephemeral range and was grabbed by an outbound connection.
Docker binds the host port at container start via the userland proxy (or via
iptables/NAT). The kernel enforces exclusivity per address:port, returning
EADDRINUSE to the second binder. Docker reports this as port is already
allocated. The fix is always to identify the current owner of the port: if it's
another container, change one mapping; if it's a host process, stop it or pick a
different host port.
# Which container (if any) already publishes this port
docker ps --format 'table {{.Names}}\t{{.Ports}}' | grep 8080
# Which process on the host owns the port (Docker or otherwise)
ss -ltnp | grep ':8080'
# Inspect the conflicting container's published ports
docker port <container>$ ss -ltnp | grep ':8080'
LISTEN 0 4096 0.0.0.0:8080 0.0.0.0:* users:(("docker-proxy",pid=2410,fd=4))
# If a non-Docker process owns it:
LISTEN 0 511 0.0.0.0:8080 0.0.0.0:* users:(("nginx",pid=812,fd=6))
$ docker ps --format 'table {{.Names}}\t{{.Ports}}'
NAMES PORTS
api 0.0.0.0:8080->8080/tcp # this container already holds 8080
-
If another container owns the port, either stop it or remap the new one:
docker run -p 8081:8080 myimage # publish on a different host port -
If a host process owns it, stop that service or choose a free host port.
-
If a stale
docker-proxyis lingering after an unclean exit, removing the old container clears it:docker rm -f <old-container>
-
In Compose, ensure each service maps to a unique host port and run
docker compose downbeforeupto release prior bindings.
docker run -d -p 8080:8080 myimage && docker ps
# Expect the container Up with the port mapping shown and no allocation error.- Reserve a clear host-port scheme per service to avoid overlaps.
- Run
docker compose down(not just stop) to release published ports. - Let Docker pick a random host port (
-p 8080, no host side) for ephemeral runs. - Avoid publishing ports already used by host daemons; check
ss -ltnpfirst.
docker · networking · ports · bind · production