Docker: Ports are not available: exposing port TCP address already in use
The daemon could not bind the host port. Find the listener, change the host side of the mapping and stop stale containers or proxies.

Introduction & Quick Summary
A container that ran yesterday refuses to start today:
docker: Error response from daemon: Ports are not available: exposing port
TCP 0.0.0.0:8080 -> 127.0.0.1:0: listen tcp 0.0.0.0:8080: bind: address already in use.Quick answer: something on the host already owns port 8080. Find it, then either remove it or publish on a different host port.
ss -ltnp 'sport = :8080' # Linux
lsof -nP -iTCP:8080 -sTCP:LISTEN # macOS
docker ps --format '{{.Names}}\t{{.Ports}}' | grep 8080
docker run --rm -p 8081:8080 myapp # different host port, same container portThe wording is precise: exposing port TCP 0.0.0.0:8080 is the host side that failed, and -> 127.0.0.1:0 says Docker had not even chosen a container port yet. The daemon tried to bind() on the host and the kernel answered EADDRINUSE. Nothing about the image is wrong, which is why rebuilding it changes nothing.
Core Mechanics, Signatures & Reproducible Setup
Publishing a port creates a host-side listener, usually a small docker-proxy process plus a NAT rule. Two listeners may not share the same protocol, address and port unless SO_REUSEPORT is set, which Docker does not do for published ports. Reproduce the collision in two commands:
python3 -m http.server 8080 &
docker run --rm -p 8080:80 nginx
# Error response from daemon: Ports are not available ...The host port is the left side of the mapping. -p 8081:80 means "listen on host 8081, forward to container 80". Changing only the host side is enough to keep the container's internal configuration untouched, so an app that hardcodes 8080 inside the image still works.
The same rule applies in Compose, where the string is the mapping:
services:
api:
build: .
ports:
- "8081:8080" # host:container
- "127.0.0.1:9229:9229"expose: documents a port for the network but never binds one on the host, so expose cannot cause this error. network_mode: host skips publishing entirely and lets the container bind directly on the host, which produces a different but related failure.
Key Comparison Table
The exact message tells you which layer is stuck:
| Message fragment | Layer | Meaning |
|---|---|---|
Ports are not available: exposing port TCP | Docker daemon | host bind failed |
bind: address already in use | kernel | some process holds the port |
bind: permission denied | kernel | privileged port without rights |
bind: cannot assign requested address | kernel | host IP does not exist on this machine |
port is already allocated | Docker network | another container claimed it |
listen tcp4 0.0.0.0:80: bind: address already in use | Docker, older wording | same as the first row |
And where a published port can be reached from, which decides whether your fix is even visible to the client:
| Published address | Host loopback | LAN | Other containers |
|---|---|---|---|
-p 8080:80 | yes | yes | no |
-p 127.0.0.1:8080:80 | yes | no | no |
-p 0.0.0.0:8080:80 | yes | yes | no |
-p [::]:8080:80 | yes, IPv6 | yes | no |
no -p, same user network | no | no | yes, via service name |
Practical Edge Cases, Error Fixes & Deep Dive Code Examples
1. Identify the holder before killing anything
sudo ss -ltnp | grep ':8080'
# LISTEN 0 4096 0.0.0.0:8080 users:(("docker-proxy",pid=41233,fd=4))
docker ps --filter "publish=8080" --format '{{.ID}} {{.Names}} {{.Status}}'A docker-proxy holder means another container owns the port; docker ps --filter publish=8080 names it. A java or node holder means a local process is running outside Docker — often a dev server you started last week. Stopping the container is safer than killing docker-proxy, because the proxy is restarted by the daemon while a killed proxy can leave a half-configured NAT rule.
The three publishing styles behave differently when the port is contested:
| Style | Host listener | Contest behaviour | Use when |
|---|---|---|---|
-p 8080:80 | 0.0.0.0:8080 and [::]:8080 | fails hard on any collision | a service must be on the host |
--network host | the app binds directly | the app's own bind error | Linux only, no NAT wanted |
| no publish, same network | none | never collides | service-to-service traffic |
2. Stale containers and leftover proxies
docker compose down # removes containers and the network
docker compose up -dA container started with --restart=always comes back automatically after a reboot and grabs the port before your new compose project starts. docker ps -a --filter status=exited reveals the old instance. When the port is held but no container appears in docker ps, restart the daemon (sudo systemctl restart docker) to clear orphaned docker-proxy processes from an interrupted upgrade.
3. Changing the host port without breaking the app
Inside the container the app still listens on 8080, and health checks, reverse proxies and browser links must use the host port instead:
services:
api:
ports: ["8081:8080"]
healthcheck:
test: ["CMD", "wget", "-qO-", "http://localhost:8080/healthz"]
proxy:
image: nginx
depends_on: [api]
ports: ["80:80"]The health check runs inside the container, so it keeps 8080. The proxy reaches api:8080 over the compose network by service name, not through the host port. Only the browser-facing URL changes, which is the one place to update documentation. If several services collide, a mapping table in the compose file beats hunting ports one by one; the Docker Compose builder validates the file before you restart the stack.
4. Windows, WSL and the reserved port range
On Windows with Hyper-V or WSL2, large ranges are excluded from dynamic allocation:
netsh int ipv4 show excludedportrange protocol=tcp
net stop winnat
net start winnatIf a port falls inside an excluded range, Docker cannot bind it even though nothing is listening. After stopping and starting WinNAT the exclusions are rebuilt and the port usually becomes free. The same symptom appears when two WSL distributions each try to publish the same port, because both bridge through the same host network stack.
5. Addresses that look free but are not
A listener on 127.0.0.1:8080 blocks 0.0.0.0:8080, because 0.0.0.0 covers every address including loopback. The reverse is also true: a container publishing on 0.0.0.0 blocks a local dev server that wants 127.0.0.1. IPv6 adds a third case — :::8080 may or may not collide with 0.0.0.0:8080 depending on net.ipv6.bindv6only, which is why the same compose file behaves differently on two hosts. When the address itself is in doubt, ip addr plus the CIDR calculator settles which interface a binding refers to.
6. Container-to-container traffic mistaken for a port problem
The other half of port troubleshooting is the opposite mistake: the port publishes fine and the client still fails because it used the wrong name.
# from another container: wrong
curl http://localhost:8080/healthz
# from another container: right
curl http://api:8080/healthzlocalhost inside a container is that container. Publishing a port does not make it reachable inside the Docker network, and DNS resolution by service name only works on a user-defined network — the default bridge network has no DNS for container names. Verify the path from the host with the cURL builder, then repeat the same request from inside a container attached to the same network before changing any mapping. One more check is worth the ten seconds: docker port api prints the actual mapping the daemon installed, which is authoritative when a stale compose file and a fresh docker run disagree.
Common Compilation/Runtime Mistakes & Version Gotchas
Rebuilding the image. The image is not involved in a host bind failure. Rebuilds only waste minutes.
Killing docker-proxy by hand. The daemon restarts it, and the port stays taken; the underlying container is what needs to stop.
Publishing a port range accidentally. -p 8000-9000:8000-9000 claims a thousand ports and produces collisions that look random. Publish only what the host must reach.
Assuming EXPOSE 8080 publishes the port. It is documentation for image users and is ignored by docker run unless -P is used.
Version notes. Docker 20.10 changed the error text to "Ports are not available" and included both sides of the mapping, which made diagnosis much easier than the older bare listen tcp4 message. Docker Desktop 4.x on macOS moved port forwarding to its own vpnkit-successor, so a port may report as busy after an unclean shutdown until Docker Desktop restarts. On Linux, enabling userland-proxy: false in daemon.json removes docker-proxy processes and relies on iptables alone, which frees ports that previously appeared as proxy-held but can change which address is reachable.
A reliable habit. Before adding a service to a compose file, check the host port once: ss -ltn | grep ':8080'. It takes a second and replaces the entire diagnosis above.
Reference material: Docker Engine networking and docker container run port publishing.
Official references
primary documentationThe Docker documentation that defines the behaviour this guide explains.
Try matching browser tools
All toolsSmall utilities that fit Docker work — they run entirely in this browser tab, so nothing you paste leaves your device.
Related Docker guides
All Docker guidesDocker build: failed to compute cache key: not found
BuildKit cannot hash a file that is not in the context. Correct the context path, the .dockerignore rules, or the COPY source and stage name.
Docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock
An endpoint mismatch, a stopped daemon, or a missing socket mount. Resolve which of the three, then start, retarget, or mount.
Docker Compose: bind: address already in use and Port Conflicts
A published port is a host socket, and two projects cannot own it. How to find the real owner, why an override file merged instead of replacing, and how.
Docker Buildx: Building Multi-Architecture Images (AMD64 & ARM64) Explained
One tag, several architectures: the driver that supports it, QEMU versus cross-compilation, registry cache, and reading the manifest list.
More in Docker
All Docker guidesThe guides filed next to this one in Docker, in library order.