Docker: port is already allocated

Fix 'port is already allocated' when Docker cannot bind a container to a host port that is in use.

Docker produces "Bind for 0.0.0.0:80: port is already allocated" when another container or host process already occupies the specified port.

What Causes This Error

Another Docker container is already mapped to the same host port. Or a host process (Nginx, Apache, MySQL) listens on the port directly.

How to Fix

  1. Find what is using the port:
sudo ss -tlnp | grep :80
  1. Stop the conflicting container or process, or map Docker to a different host port:
docker run -p 8080:80 nginx:latest