port is already allocated
port is already allocated
DodaTech
2 min read
The “port is already allocated” error occurs when Docker tries to bind a container port to a host port that is already in use. Docker cannot share a host port between multiple processes. You must free the port or use a different one.
What It Means
Docker attempted to publish a container port to a host port (e.g., -p 8080:80) but that host port is already bound. The conflict can come from another Docker container, a system service, or any other process.
Why It Happens
- Another Docker container is already using the same host port mapping.
- A non-Docker process (e.g., nginx, Apache, a dev server) is listening on that port.
- A previously stopped container still holds the port binding.
- Docker did not release the port after a crash or improper shutdown.
How to Fix It
1. List running containers and their ports
docker ps --format "table {{.Names}}\t{{.Ports}}"Stop any container that is using the conflicting port:
docker stop <container-name>2. Find which process owns the port
sudo lsof -i :8080Or using ss:
sudo ss -tlnp | grep :8080Kill the process if it is safe to do so:
sudo kill -9 <PID>3. Use a different host port
Re-run your container with an alternate port mapping:
docker run -p 8081:80 nginxUse -p HOST_PORT:CONTAINER_PORT where HOST_PORT is unique.
4. Remove stopped containers holding the port
docker rm -f $(docker ps -a -q --filter "status=exited")5. Restart Docker (last resort)
sudo systemctl restart dockerFAQs
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro