Skip to main content
⚡ OpenDevDocs
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 use

Symptoms

  • docker run -p 3000:3000 or docker compose up fails to start.
  • The container immediately terminates or fails during initialization.
  • Error message states port is already allocated or bind: 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:

  1. An existing background Docker container is already publishing that port.
  2. A native host service (e.g. local PostgreSQL running via systemd or 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 stop

Step-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"
```

On this page