Fix "Bind for 0.0.0.0:8080 failed: port is already allocated" (Docker)
Error response from daemon: driver failed programming external connectivity on endpoint web (3f1c9a2b7d4e): 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
- Error response from daemon: Ports are not available: exposing port TCP 0.0.0.0:8080 -> 0.0.0.0:0: listen tcp 0.0.0.0:8080: bind: An attempt was made to access a socket in a way forbidden by its access permissions.
- Error: listen EADDRINUSE: address already in use :::3000
- OSError: [Errno 98] Address already in use
- Only one usage of each socket address (protocol/network address/port) is normally permitted.
The host port you publish with -p 8080:80 is already taken, by another container or by a local program. Find who holds it (docker ps, lsof, Get-NetTCPConnection), stop it, or publish on another port, for example -p 8081:80.
What this error means
Publishing a port (-p 8080:80 or ports: in Compose) asks Docker to listen on host port 8080 and forward to the container. A TCP port can only be listened on by one process at a time on a given address. "port is already allocated" means Docker already assigned it to another container; "address already in use" (EADDRINUSE) comes from the operating system, when a process outside Docker (Node server, Apache, local MySQL…) is already listening. The container is created but does not start.
Common causes
- Another container already publishes this port: often an old
docker compose upfrom another project, or a container with arestart: alwayspolicy that came back up. - A local service listens on the port: a dev server (
npm run dev,php artisan serve), Apache/Nginx, MySQL or PostgreSQL installed on the machine. - Same port published twice in the same
compose.yaml, or two replicas of a service with a fixed host port. - Windows: port range reserved by Hyper-V/WSL (WinNAT). The error then says "forbidden by its access permissions" even though no program is listening.
- Ghost Docker proxy: after a crash, the daemon keeps the port reserved until it restarts.
Step-by-step fix
-
Find the container publishing this port
List containers (including stopped ones) that publish port 8080. If one shows up, that is the culprit.
docker ps -a --filter "publish=8080" docker ps --format "table {{.Names}}\t{{.Ports}}" -
Stop that container
Stop it, or stop the whole Compose project it belongs to from its folder.
docker compose downremoves the containers but keeps the volumes (without-v).docker stop <container_name> # or, from the other project's folder docker compose down -
Linux / macOS: find the local process
If no container shows up, a system program is listening.
lsofgives the PID; on Linux,ssworks too.sudois needed to see other users’ processes.sudo lsof -nP -iTCP:8080 -sTCP:LISTEN # Linux alternative sudo ss -ltnp 'sport = :8080' # then stop it gracefully kill <PID> -
Windows: find the local process
In PowerShell, get the listening PID and then the program name.
netstat -anogives the same information in the classic command prompt.$p = (Get-NetTCPConnection -LocalPort 8080 -State Listen).OwningProcess Get-Process -Id $p Stop-Process -Id $p # cmd alternative: netstat -ano | findstr :8080 -
Or publish on another port
If you want to keep the other service, only change the host port (left side). An environment variable avoids conflicts between developers.
services: web: image: nginx:1.27 ports: - "${APP_PORT:-8081}:80" -
Windows: check reserved ports
If nothing is listening but the error persists, look at the ranges excluded by Windows. Restarting the WinNAT service (admin PowerShell) often frees the range; otherwise pick a port outside those ranges.
netsh interface ipv4 show excludedportrange protocol=tcp net stop winnat net start winnat -
Restart Docker as a last resort
If the port stays reserved while no container or process uses it, restart the daemon (Linux) or Docker Desktop (macOS/Windows).
sudo systemctl restart docker
Did this fix work for you?
Confirm it in one click: it will rise for the next developers stuck on the same error.
Keep it from coming back
- Make ports configurable (
${APP_PORT:-8080}:80) and document them in.env.example. - Stop your projects with
docker compose downinstead of closing the terminal, and avoidrestart: alwaysin development. - Only publish what must be reachable from the host: internal services (database, Redis) talk over the Compose network without
ports:.
Frequently asked questions
How do I find which program uses port 8080?
On Linux and macOS: sudo lsof -nP -iTCP:8080 -sTCP:LISTEN. On Windows: Get-NetTCPConnection -LocalPort 8080 -State Listen then Get-Process -Id <PID>.
What is the difference between "port is already allocated" and "address already in use"?
The first comes from Docker: another container already has that port. The second comes from the OS: a process, Docker or not, is already listening on that address.
Can two containers use the same port?
Yes inside (each has its own network), but not the same published host port. Publish them on different host ports or put a reverse proxy in front.
Useful tools for this error
More Docker & DevOps errors
- Fix "permission denied while trying to connect to the Docker daemon socket"
- Fix "no space left on device" (Docker and Linux)
- Fix "exec format error" in Docker (arm64 / amd64)
- Fix "Cannot connect to the Docker daemon. Is the docker daemon running?"
- Fix "connect() failed (111: Connection refused) while connecting to upstream" (Nginx 502)
- Fix "exited with code 137" (OOMKilled) in Docker and Kubernetes
- Fix "CrashLoopBackOff" / "Back-off restarting failed container" (Kubernetes)