Fix Docker Error: 'Bind for 0.0.0.0:port failed: address already in use'
Identify and terminate conflicting host processes or adjust Docker port mapping to resolve port bind collisions.
Error response from daemon: driver failed programming external connectivity on endpoint web: Bind for 0.0.0.0:5432 failed: port is already allocated
# Step 1: Find which process is locking port 5432
# Linux / macOS:
lsof -i :5432
# Windows (PowerShell):
Get-Process -Id (Get-NetTCPConnection -LocalPort 5432).OwningProcess
# Step 2: Stop existing Docker containers holding the port:
docker stop $(docker ps -q --filter "publish=5432")
# Step 3: Or remap to non-conflicting host port 5433 in docker-compose.yml:
services:
app:
ports:
- "5433:5432"Root Cause & Mechanism Analysis
Why does this error occur?
A local service running on the host OS (such as local PostgreSQL, Nginx, Apache, or a previous unstopped Docker container) is already bound and listening to the requested host port.
Frequently Asked Questions
Does changing the host port change the port inside the container?
Related Developer Error Solutions
Browse All 35 GuidesDocker: no space left on device
Clean dangling Docker build caches, unused volumes, and stopped containers to free disk space.
PostgreSQL: Remaining Connection Slots Reserved
Resolve PostgreSQL connection exhaustion caused by connection leaks or missing pooling with PgBouncer / Prisma Accelerate.
Nginx 502 Bad Gateway
Resolve reverse proxy gateway errors when Nginx cannot establish a connection with Node.js, Next.js, or Gunicorn backends.