Error response from daemon: Ports are not available: exposing port TCP 0.0.0.0:5432 -> 0.0.0.0:0 (Docker) — how to fix
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: An attempt was made to access a socket in a way forbidden by its access permissions.
Error response from daemon: Ports are not available: exposing port TCP 0.0.0.0:3000 -> 0.0.0.0:0: listen tcp 0.0.0.0:3000: bind: address already in use
Quick fix: Windows: run netsh interface ipv4 show excludedportrange protocol=tcp; if your port is listed, restart WinNAT in an admin terminal (net stop winnat then net start winnat) or publish a different host port (-p 15432:5432). 'address already in use': find the process with netstat -ano | findstr :5432 (Windows) or lsof -i :5432 (macOS) and stop it.
What it means
When you publish a port (-p 5432:5432 or ports: in Compose), Docker Desktop has to listen on that port on your host. Ports are not available means that listen call failed. The text after bind: tells you why.
If another container already uses the port, Docker usually reports port is already allocated instead.
Cause 1 (Windows): the port is in an excluded range
An attempt was made to access a socket in a way forbidden by its access permissions usually means Windows reserved the port. Hyper-V, WSL2 and WinNAT reserve blocks of ports at boot, and the blocks can land on common dev ports (3000, 5432, 8080...). Check in PowerShell or cmd:
netsh interface ipv4 show excludedportrange protocol=tcp
Start Port End Port
---------- --------
5357 5357
5380 5479
If your port falls inside a range, restart WinNAT from an Administrator terminal, which frees its dynamic reservations:
net stop winnat
docker start mycontainer
net start winnat
Starting your container while WinNAT is stopped lets Docker take the port before the reservation comes back.
Reservations can change on every reboot. To keep them away from your dev ports, you can move the dynamic port range (Admin terminal, then reboot):
netsh int ipv4 show dynamicport tcp
netsh int ipv4 set dynamic tcp start=49152 num=16384
Or reserve your port for yourself so Hyper-V can't take it (run while the port is free):
netsh int ipv4 add excludedportrange protocol=tcp startport=5432 numberofports=1
Cause 2: another program is listening (address already in use)
A local PostgreSQL, Node dev server, IIS or another tool holds the port.
Windows:
netstat -ano | findstr :5432
tasklist /FI "PID eq 1234"
macOS / Linux:
lsof -nP -iTCP:5432 -sTCP:LISTEN
Stop that service (e.g. brew services stop postgresql, or stop the Windows service in services.msc), or use another host port as in the next fix. On macOS, port 5000 and 7000 are commonly taken by the AirPlay Receiver (System Settings → General → AirDrop & Handoff).
Fix 3: just map a different host port
The container's internal port can stay the same; only the left side must be free:
docker run -p 15432:5432 postgres:16
services:
db:
image: postgres:16
ports:
- "15432:5432"
Connect to localhost:15432 from the host. Other containers on the same Compose network still use db:5432. If you're converting a docker run command, the docker run to Compose converter keeps the mapping right.
Fix 4: restart Docker Desktop
Stale port forwards from crashed containers can keep a port busy inside Docker Desktop's own proxy. Quit Docker Desktop fully, or on Windows run wsl --shutdown, then start it again.
Check
docker ps --format "table {{.Names}}\t{{.Ports}}"
Your container should show 0.0.0.0:5432->5432/tcp (or your new host port).
Last updated 2026-12-05.