Skip to main content
Fix Docker "Port Is Already Allocated"

Fix Docker "Port Is Already Allocated"

KU
· Founder & Chief Editor
• 8 min read•Updated •80 views

You run docker run, and it refuses to bind port 8080. Something already owns that port. Here is how to find the holder and get your container up.

Key takeaways

  • Docker's "Bind for 0.0.0.0:8080 failed: port is already allocated" means something already holds that host port, usually another container or a forgotten dev server.
  • Find it with docker ps -a --filter publish=8080, then sudo ss -ltnp.
  • Stop or remove the holder, or change the left side of -p to a free host port.

Docker's "Bind for 0.0.0.0:8080 failed: port is already allocated" means another container or host process already owns host port 8080. Find the holder with docker ps -a --filter publish=8080, then sudo ss -ltnp | grep :8080 if Docker shows nothing. Stop or remove it, or publish to a free host port instead, for example -p 8081:80.

Verified against

Docker Engine 29.9 (29.9.2, released 2026-10-20), against the docs.docker.com port publishing page, the docker container ls reference and the ss(8) man page. Checked October 2026.

You run the container you have run a hundred times, and Docker throws this back:

code
$ docker run -d --name web -p 8080:80 nginx
docker: Error response from daemon: driver failed programming external
connectivity on endpoint web (a1b2c3...): Bind for 0.0.0.0:8080 failed:
port is already allocated.

With -p 8080:80, Docker maps port 8080 on the host to port 80 in the container. With no host address in the flag, the docs say it binds every host address, 0.0.0.0 and [::]. If anything already owns 8080, the bind fails and the container never starts.

The number on the left is the one that fights over the host. The number on the right lives inside the container's own network namespace and never conflicts with anything on the host. Almost every "port is already allocated" error is about the left number.

Find who owns the port, in this order

There are three suspects: a running container, a stopped container that still holds the mapping, or a regular process on the host. Check Docker first because it is the fast one, and include stopped containers from the start:

code
$ docker ps -a --filter publish=8080
CONTAINER ID   IMAGE   STATUS          PORTS                  NAMES
7f9c1a2b3d4e   nginx   Up 3 days       0.0.0.0:8080->80/tcp   old-web

A hit is your culprit. Stop it and, if you do not need it, remove it:

code
$ docker stop old-web
$ docker rm old-web
$ docker run -d --name web -p 8080:80 nginx

If Docker comes back empty, the port belongs to something that is not a container. Ask the kernel. ss ships with iproute2 and is on almost every Linux box; -l shows listeners, -t TCP, -n numeric ports, -p the owning process:

code
$ sudo ss -ltnp 'sport = :8080'
State  Recv-Q Send-Q Local Address:Port  Peer Address:Port Process
LISTEN 0      511    0.0.0.0:8080        0.0.0.0:*     users:(("node",pid=18422,fd=22))

On macOS, or if you prefer it, lsof gives the same answer:

code
$ sudo lsof -nP -iTCP:8080 -sTCP:LISTEN
COMMAND   PID  USER   FD   TYPE  DEVICE SIZE/OFF NODE NAME
node    18422 kiril   22u  IPv4  ...    0t0      TCP *:8080 (LISTEN)

There it is: a stray node dev server on PID 18422, left running days ago. A forgotten local dev server is a very common cause. If the process listed is docker-proxy, a container owns the port after all, possibly in another Compose project; go back to docker ps -a. On Docker Desktop for Mac, the holder shows up as a Docker backend process for the same reason.

Fix it: evict the holder or move your port

Once you know who holds the port, you have two honest options.

Option A: stop the holder. Reasonable when it is a leftover process you actually want gone.

code
$ kill 18422
$ sleep 2; sudo ss -ltn 'sport = :8080'   # still listed? it ignored SIGTERM
$ kill -9 18422

Reach for kill -9 only after a plain kill fails. A process killed with SIGKILL gets no chance to flush or clean up.

Option B: move your container to a free host port. This is the option we reach for most, because whatever is on 8080 is often something you also want running. Change only the host side of the mapping:

code
$ docker run -d --name web -p 8081:80 nginx
$ curl -sI localhost:8081 | head -1
HTTP/1.1 200 OK

The container still listens on 80 internally; you reach it on localhost:8081. If you do not care which host port you get, leave the host side off and let Docker pick a free one:

code
$ docker run -d --name web2 -p 80 nginx
$ docker port web2
80/tcp -> 0.0.0.0:32768

Compose leftovers and double-publishing

An old Compose stack from a previous branch or project is the next most common holder. Tear it down from that project's directory, which stops and removes every service and releases their ports in one shot:

code
$ docker compose ls
$ docker compose -p old-project down

The self-inflicted version: two services in one Compose file both asking for the same host port. The second one fails the moment it starts. Grep for it:

code
$ grep -nE '"?8080:' compose.yaml docker-compose.yml 2>/dev/null

If you find two, give one a different host port. This is also where expose versus ports confusion bites. expose only documents that a container listens on a port; it binds nothing on the host and never causes this error. Only ports (and -p) publish to the host, and only published ports collide. For containers that only talk to each other, drop ports entirely and use the service name on the Compose network.

The error strings, and what each one means

Error textCauseFix
Bind for 0.0.0.0:8080 failed: port is already allocatedAnother container (running or restarting) publishes 8080docker ps -a --filter publish=8080, then stop and rm it
listen tcp4 0.0.0.0:8080: bind: address already in useA non-Docker process listens on 8080sudo ss -ltnp 'sport = :8080', stop it or remap
Bind for [::]:8080 failed: port is already allocatedSame conflict on the IPv6 wildcardSame checks; look for [::]:8080 in ss output
cannot expose privileged port 80Rootless Docker cannot bind ports below 1024Publish -p 8080:80, or lower net.ipv4.ip_unprivileged_port_start
Error persists, nothing holds the portStale daemon port bookkeeping after a crashsudo systemctl restart docker

The stopped-container row deserves a word. A container that is stopped but not removed keeps its port mapping, and with a restart policy like unless-stopped or always it grabs the port again whenever the daemon restarts, often before your new container does. Plain docker ps lists only running containers, which is why the -a flag belongs in the very first command. If you also hit socket errors while doing this, the Docker permission denied fix covers the neighboring problem.

Where this breaks

Nothing here applies when Docker is not the one binding host ports. With --network host, the container shares the host's network stack and there is no mapping to change, so the app itself must listen elsewhere. On Kubernetes, hostPort conflicts surface as unschedulable pods, not this error. And on a remote DOCKER_HOST or a Docker Desktop VM, ss on your laptop inspects the wrong machine: run it where the daemon runs.

Questions people ask

What does "Bind for 0.0.0.0:8080 failed: port is already allocated" mean?

Docker tried to publish host port 8080 on every IPv4 address and found it already taken. The 0.0.0.0 part means "all interfaces", not a specific address. The port is the left side of your -p flag, so either free that host port by stopping whatever holds it, or choose a different host port. The container-side number on the right is never the problem.

How do I find which container is using a port?

Run docker ps -a --filter publish=8080. The publish filter matches containers that publish that port, and -a includes stopped ones, which still hold their mapping. If the list is empty, the holder is a regular process: sudo ss -ltnp 'sport = :8080' on Linux or sudo lsof -nP -iTCP:8080 -sTCP:LISTEN on macOS prints its name and PID.

Can I bind the container only to localhost to avoid conflicts?

Publishing with -p 127.0.0.1:8080:80 limits access to the Docker host itself, which is a good security default for dev databases. It does not avoid conflicts: it still collides with anything listening on 127.0.0.1:8080 or the 0.0.0.0:8080 wildcard. To avoid a conflict, pick an unused host port or let Docker choose one with -p 80.

The call we'd make

Run docker ps -a --filter publish=8080 first, every time; it answers the question in one line for most cases and catches the stopped-container reservation. If it comes back empty, go straight to ss for the non-Docker holder. When the port belongs to something you also want running, remap your container and move on; killing processes to reclaim 8080 eventually costs you the wrong process at the wrong time. If you are new to how -p fits together with images and containers, our first-container tutorial walks through it, and the broader map lives in the Docker troubleshooting guide.

Sources

Explore topics:DockerDevOps
React
Share this post
Cite this article
Plain text

Kiril Urbonas (2026). Fix Docker "Port Is Already Allocated". DevOpsNess. Updated 2026-10-31. https://www.devopsness.com/blog/fix-docker-port-already-allocated

Markdown

[Fix Docker "Port Is Already Allocated"](https://www.devopsness.com/blog/fix-docker-port-already-allocated) (Kiril Urbonas, DevOpsNess, updated 2026-10-31)

KU

Kiril Urbonas

Founder & Chief Editor

586 articles
View all articles by Kiril Urbonas

You might have missed

Evergreen posts worth revisiting.