docker port already allocated — how to fix
Quick Answer
# Find what is using the port (e.g. 8080)
sudo lsof -i :8080
# or
ss -tlnp | grep 8080
# Stop the conflicting container
docker ps | grep 8080
docker stop <container-id>
# Or kill the non-Docker process
sudo kill -9 <PID>
When this happens
Error response from daemon: driver failed programming external connectivity on endpoint my-app:
Bind for 0.0.0.0:8080 failed: port is already allocated
Another process or Docker container is already listening on the same host port.
Other causes & fixes
Use a different host port
Map a different host port to the same container port:
# Map host port 8081 → container port 8080
docker run -p 8081:8080 my-image
Stop all containers on a given port
docker ps --filter "publish=8080" -q | xargs docker stop
On macOS: AirPlay Receiver uses port 5000 / 7000
Disable AirPlay Receiver in System Settings → General → AirDrop & Handoff.
# Verify
sudo lsof -iTCP:5000 -sTCP:LISTEN
Related