Error: Bind for 0.0.0.0:3000 failed: port is already allocated
Educational use only. Content explains errors and defensive fixes for systems you own or are authorised to test. Do not use any technique here to access data, accounts, or networks without permission.
Root Cause
This Docker daemon error appears when you attempt to start a container that binds to a host port which is already in use by another process or another running container. Docker maps container ports to host ports using the -p flag (e.g., -p 3000:3000), and the host operating system will reject the binding if the specified port is occupied. This commonly happens during development when a previous container was not properly stopped, when a local development server (Node, Python, etc.) is already listening on the same port, or when docker-compose is restarted without first bringing down the old stack. On macOS and Windows, background services or AirPlay receivers sometimes silently claim popular ports like 5000 or 7000, adding to the confusion.
Fix / Solution
Identify the conflicting process with `lsof -i :3000` (macOS/Linux) or `netstat -ano | findstr :3000` (Windows). Stop the offending process or container, or remap your new container to a different host port (e.g., -p 3001:3000). For docker-compose, always run `docker-compose down` before `docker-compose up`.
Code Snippet
# Find what is using port 3000
lsof -i :3000
# Kill the process (replace PID)
kill -9 <PID>
# Or remap to a different host port
docker run -p 3001:3000 my-app
# Docker Compose — clean restart
docker-compose down && docker-compose up -d