docker
network_error
ai_generated
true
Bind for 0.0.0.0:PORT failed: port is already allocated
ID: docker/port-already-allocated
92%Fix Rate
94%Confidence
50Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 24 | active | — | — | — |
Root Cause
The host port is already in use by another container or process. Cannot bind two services to the same port.
genericWorkarounds
-
92% success Find and stop the process or container using the port
# Find what's using the port: lsof -i :8080 # or: ss -tlnp | grep 8080 # If it's a Docker container: docker ps --filter 'publish=8080' docker stop <container_id> # If it's a host process: kill <pid>
Sources: https://docs.docker.com/network/
-
88% success Use Docker Compose to manage port allocation conflicts
# In docker-compose.yml, map to a different host port: services: web: ports: - '8081:8080' # host:container # Use 'docker compose down' before 'docker compose up' to ensure old containers release ports. # Use 'docker compose up --force-recreate' if containers are stuck. -
85% success Bind to 0.0.0.0 and let Docker assign a random host port
# Use -P to publish all exposed ports to random host ports: docker run -P myimage # Or specify only the container port (random host port assigned): docker run -p 8080 myimage # Find the assigned port: docker port <container_name> 8080
Sources: https://docs.docker.com/network/
Dead Ends
Common approaches that don't work:
-
Killing the process using the port without checking what it is
60% fail
May kill a critical service; always identify the process first
Error Chain
Frequently confused with: