Australian cloud for business software — built and run in Sydney since 2002

NetLeverage
NetLeverage

Docker Bind for 0.0.0.0:80 failed: port is already allocated

Technical article
Troubleshooting

About this article: This article is reviewed against the cited sources. This is source research, not lab validation. Check the stated versions and your own requirements before making changes.

A container fails to start with Bind for 0.0.0.0:80 failed: port is already allocated. Docker tracks every host address and port it has published, and it refused a second publication of the same one. The holder can be another container, an old copy of the same stack, or a Swarm service. A web server on the host that owns the port gives a different message, covered in bind() to 0.0.0.0:80 failed (98: Address already in use): nginx or Apache will not start.

What the error means

In the Docker Engine source the message is built as Bind for %s:%d failed: port is already allocated, with the host IP and port filled in. It is raised by Docker's own port allocator when a request names a specific port that the allocator already holds for that address. In the source, the allocator returns it from the code that checks the port database before binding.

The full text can have a prefix. In the source, a failure while setting up external connectivity for a container is reported as driver failed programming external connectivity on endpoint followed by the container name, its endpoint ID and the underlying error. So a full line can have that prefix and end with Bind for 0.0.0.0:80 failed: port is already allocated.

The -p flag publishes a container port to the host. Docker's port publishing page lists -p 8080:80 (host port 8080 to container port 80) and -p 192.168.1.100:8080:80 (a specific host address), and says that with no host address given, Docker publishes to all host addresses (0.0.0.0 and [::]). The Compose file reference says the same for the short syntax: if you do not give a host IP, it binds to 0.0.0.0. It also says that when only the container port is given, the container runtime allocates an unassigned port on the host.

Likely causes

Cause What you see How to confirm
Another container already publishes the host port The new container fails to start and prints the error docker ps -a lists a container whose PORTS column contains 0.0.0.0:80->
An older copy of the same Compose stack is still running, or a second project uses the same mapping Starting a second stack fails; the first still works docker ps shows two project name prefixes; docker compose config shows the mapping
Two services in one Compose file map the same host port The stack fails on the second service every time docker compose config prints two published values that match
A Swarm service publishes the port The port is held but no container you can see publishes it The Docker page says Swarm services are always exposed on the 0.0.0.0 interface; check the Swarm services on the cluster
A process outside Docker owns the port A different message such as address already in use, not already allocated ss -ltnp shows a non-Docker process on that port
Docker's record does not match what you can see Neither docker ps -a nor ss shows a holder Your client may be talking to a different engine than the one holding the port (DOCKER_HOST is set), or a Swarm service holds it

Prove the cause before changing anything

All read-only.

1. Which containers publish that host port? Include stopped ones:

docker ps -a

-a shows all states, because the default list shows only running containers. Read the PORTS column for a mapping that begins with the host address and port, for example 0.0.0.0:80->80/tcp. Do not rely on docker ps --filter publish=80 for this. The Docker documentation lists the filter publish or expose, but its own example publishes container port 80 and shows it mapped as 0.0.0.0:32768->80/tcp, so the filter matches the container port. A container that maps host port 80 to container port 8080 would therefore probably be missed.

2. What is listening on the host?

ss -ltnp

The ss manual defines -l as listening sockets, -t as TCP, -n as numeric and -p as showing the processes using sockets. Look for :80 in the output. Note the program named in the last column. If it is not a Docker process, you are looking at the host-service case, bind() to 0.0.0.0:80 failed (98: Address already in use): nginx or Apache will not start.

3. Which engine are you talking to?

echo "$DOCKER_HOST"

An empty value means the local default. A value means your commands run against another engine.

4. If you use Compose, read the resolved file.

docker compose config

The Docker reference describes this as rendering the actual data model, merging files, resolving variables and expanding short notation into the canonical form. Search the output for the failing port.

5. If Swarm is in use, check the cluster's services for a published port 80.

Fix

Pick the least disruptive change.

1. Give the new container a different host port. This changes nothing for the existing service. Use a mapping such as -p 8080:80, or in a Compose file "8080:80" (the reference says to quote HOST:CONTAINER). If a reverse proxy or firewall rule points at the old port, update it to match.

2. Bind to a specific address. Two mappings can use the same host port number only if both name different specific host addresses, for example -p 192.168.1.100:8080:80, which binds to one address only. Docker's port allocator also checks the 0.0.0.0 entry: the source says that when the request names specific addresses, the port needs to be free in the per-address maps for those addresses "and the map for 0.0.0.0/::". So if the other container publishes 0.0.0.0:80, a request for 192.168.1.100:80 still fails with the same error. Use a different host port as in step 1, or first move the other container to a specific address. Docker's page also shows -p 127.0.0.1:8080:80 for a port reachable only from the host. This is also the safer choice when a service does not need to be public.

3. Stop the other container (if it should not be running). First save its configuration and identify exactly which container holds the port:

docker ps -a
docker inspect OLDNAME > /root/OLDNAME-inspect-2026-11-20.json

Disruptive step: stopping the container with docker stop ends the service that container provides, and any users of it lose the service. The Docker reference says the main process receives SIGTERM and, after a grace period, SIGKILL, and the default grace period is 10 seconds on Linux. Back-out: docker start OLDNAME, which restarts the container with the configuration it already had.

Replace OLDNAME with the name of the container whose PORTS entry shows the host port, from the first command. Then:

docker stop OLDNAME

Avoid docker rm -f as a first move: removal deletes the container, and -f uses SIGKILL on a running one, per the Docker reference. Remove only after you have confirmed what the container holds, for example data in anonymous volumes.

4. For a Compose duplicate, copy the compose file with a dated name before you edit it (cp -p docker-compose.yml docker-compose.yml.2026-11-20.bak), change the mapping, then check it:

docker compose config

Risk: starting the stack with the changed file interrupts services: the Docker reference says docker compose up picks up changes by stopping and recreating containers whose service configuration or image changed. If the output shows the intended mappings, start the stack in the background with docker compose up -d. Back-out: restore the saved file under its dated name (cp -p docker-compose.yml.2026-11-20.bak docker-compose.yml), run docker compose config again, then docker compose up -d.

5. If nothing visible holds the port, check whether DOCKER_HOST points at a different engine and whether a Swarm service publishes it. Do not restart the Docker daemon as a guess: the Docker page on exit code 137 lists a daemon restart as an event that kills all running containers.

Example (illustrative): on web01, a deploy of shop-new fails with Bind for 0.0.0.0:80 failed: port is already allocated. docker ps -a shows shop-old, running, with 0.0.0.0:80->80/tcp in its PORTS column. ss -ltnp shows a Docker process on port 80 and no other program. The team decides the new version should replace the old one after a short maintenance window. They save docker inspect shop-old to a dated file, run docker stop shop-old, start shop-new, and keep shop-old stopped but not removed until the release is accepted. The back-out is docker stop shop-new then docker start shop-old.

Confirm the fix

The new container should show Up in docker ps, with the expected PORTS mapping. Run ss -ltnp again and confirm the port is held by the right container. Test the service from a client with the check you normally use. Then check that the old service, if it was supposed to keep running, still answers on its own port.

What to watch afterwards

  • Duplicate port numbers across Compose files and docker run scripts; keep a table of host ports per server.
  • Containers that keep restarting; as general advice, read their logs for this error.
  • Published ports without a host address: Docker's page warns that publishing to all interfaces can make a port available outside the host.
  • Leftover stopped containers from past deploys that you meant to remove.

Risks and limits

Stopping a container stops the service it provides, and removing one deletes it. The port allocator message is generated by Docker, so it does not appear when a host program holds the port. Docker's behaviour differs in detail between engine versions and with Swarm; the message wording given here is from the source versions named in the front matter. These commands have not been run or lab-tested.

Sources