Docker Errors
devopsdockerTroubleshootingBeginner
Docker: Bind for 0.0.0.0:PORT failed: port is already allocated
Fix port conflict errors in Docker and Docker Compose when another container or host service is already listening on the requested port.
Verified: 2026-09-30
Tested on:docker 27.x
Platforms:
linuxmacoswindows
#docker#networking#ports#errors
Error Message
docker: Error response from daemon: driver failed programming external connectivity on endpoint my-app:
Bind for 0.0.0.0:3000 failed: port is already allocated.or in Docker Compose:
Error response from daemon: Ports are not available: exposing port TCP 0.0.0.0:5432 -> 0.0.0.0:0: listen tcp 0.0.0.0:5432: bind: address already in useSymptoms
docker run -p 3000:3000ordocker compose upfails to start.- The container immediately terminates or fails during initialization.
- Error message states
port is already allocatedorbind: address already in use.
Why It Happens
A network port on a given network interface (e.g. 0.0.0.0:3000) can only be bound by one single operating system process at any given moment. This error happens when:
- An existing background Docker container is already publishing that port.
- A native host service (e.g. local PostgreSQL running via
systemdor Homebrew, or a stray Node.js process) is already listening on the host port.
Quick Fix (1-Liner)
Check and stop the conflicting Docker container:
docker ps --filter "publish=3000" --format "{{.ID}}" | xargs -r docker stopStep-by-Step Fix
**Check native host processes (macOS/Linux):**
```bash
# Find process ID using port 3000
lsof -i :3000
# or with ss
ss -tulpn | grep 3000
```
**Check native host processes (Windows PowerShell):**
```powershell
Get-NetTCPConnection -LocalPort 3000 | Format-Table -Property OwningProcess
```If it is a host process (e.g. PID 14232):
```bash
# Try graceful kill first:
kill 14232
# If unresponsive:
kill -9 14232
```
<Callout type="warning">
Ensure the process identified by `lsof -i :<port>` is indeed your previous stopped dev instance before killing it. Avoid terminating essential database daemons or system processes.
</Callout>```bash
# Map host port 3001 to container port 3000
docker run -d -p 3001:3000 my-image
```
In `compose.yaml`:
```yaml
ports:
- "3001:3000"
```Related Topics
Updates were rejected: non-fast-forward push
Safely resolve Git rejected push errors by rebasing and reconciling divergent remote history without data loss.
Docker: permission denied while connecting to daemon socket
Fix Linux Docker daemon permission errors without needing to run sudo docker on every command.