Ran docker compose up and got: 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.
Root cause:
A previous docker compose up run wasn't cleanly stopped — the container was still running in the background with the port bound. Alternatively, a local PostgreSQL service installed on the host was already listening on 5432.
Fix:
First, bring down any existing Compose stack cleanly:
docker compose downIf that doesn't free the port, find what process is holding it:
# Linux / macOS
lsof -i :5432
# or
ss -tlnp | grep 5432
# Windows
netstat -ano | findstr :5432Kill the process or stop the conflicting service:
# If it's a local postgres service
sudo systemctl stop postgresql
# If it's a stale Docker container
docker ps -a | grep 5432
docker rm -f <container_id>If you want to keep both running, map to a different host port in compose.yaml:
services:
db:
image: postgres:16
ports:
- "5433:5432" # host:container — changed host port to 5433Lesson: Always run docker compose down before docker compose up if you're unsure of the current state — orphaned containers from previous sessions are the most common cause of port conflicts.