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 -a to 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.

Looking for reliable cloud infrastructure? Check out these developer-friendly services.