FULL AI ANALYSIS

Docker: container fails to start with 'bind: address already in use' when publishing port

Generated Oct 31, 2026, 9:27:03 AM

Analysis summary

Port binding collisions can occur when a host process already listens on the requested host port or when Docker's socket proxy from an existing container/supervisor holds the port. Diagnosis requires identifying the current listener, checking Docker port-mapping conflicts and systemd services, and validating whether binding to a different host interface (127.0.0.1 vs 0.0.0.0) is acceptable.

Possible causes

Host process (systemd service or user process) is already listening on the requested host port

85%

A previously started container bound the port but terminated abnormally leaving the host socket in TIME_WAIT or a listening proxy (rare)

40%

Docker daemon-level socket or conflict with host network namespace mapping (host networking mode)

30%

Suggested fixes

1

Diagnostic step 1

Run sudo ss -lntp | grep :3000 (or sudo lsof -iTCP:3000 -sTCP:LISTEN) to identify the process and PID listening on the host port. Result meaning: If output shows a PID and process name (systemd, nginx, node, etc.), that process is the current owner and must be stopped or reconfigured. If no process is shown but kernel shows TIME_WAIT only, a previous connection may linger (temporary). If docker-proxy appears, an existing container or stale mapping is holding the port.

2

Diagnostic step 2

List Docker containers and their published ports: docker ps --format '{{.ID}} {{.Names}} {{.Ports}}'. Result meaning: If an existing container publishes the same host port, stop or remove that container to free the port. If no container shows the port, the listener is a host process.

3

Diagnostic step 3

Check systemd for services configured to use the port: sudo systemctl list-sockets | grep 3000 and inspect unit files in /etc/systemd/system and /lib/systemd. Result meaning: If a systemd socket unit owns the port, disable or reconfigure the unit instead of killing processes directly; disabling is reversible with systemctl enable/start unit restore.

4

Diagnostic step 4

Attempt binding container to a different host port temporarily: docker run -p 127.0.0.1:3001:3000 image and verify the service is reachable on localhost:3001. Result meaning: If the container runs and is reachable, the problem is a host-level port conflict; using an alternate host port is a safe workaround. If binding to 127.0.0.1 succeeds but 0.0.0.0 fails, an external service is occupying the 0.0.0.0 address.