Symptom
Error response from daemon: Bind for 0.0.0.0:8080 failed: port is already allocated
Solutions
Use a Different Port
docker run -d -p 8081:80 nginx
Find and Release the Port in Use
Windows
netstat -ano | findstr :8080
Then terminate the relevant process in Task Manager.
Mac/Linux
lsof -i :8080
kill -9 PID
Stop a Running Docker Container
docker ps
docker stop <container-id>
Key Points
- A previously started container often lingers and occupies the port
- Use
docker ps -ato see stopped containers as well
For identifying and terminating the process using a port, How to Check and Kill Linux Processes (ps/kill) is also a useful reference.
Related Articles
- Docker Basic Commands Cheatsheet
- How to Use docker-compose
- nginx 502 Bad Gateway: Causes and Fixes
- How to Check and Kill Linux Processes (ps/kill)
Recommended Cloud Hosting
Looking for reliable cloud infrastructure? Check out these developer-friendly services.
- Cherry Servers - High-performance VPS and dedicated servers
- Cloudways - Managed cloud hosting for developers