Docker: container fails to start with 'bind: address already in use' when publishing port
Environment
Ubuntu 22.04 host running Docker Engine 24.x; container image is a Node.js web server publishing port 3000; deployment via docker run -p 3000:3000.
Symptoms
docker run fails immediately with an error mentioning bind/address in use; container does not start and no application logs are produced inside the container.
Observations
The host already runs other services (systemd unit and a test nginx). netstat shows entries for tcp 0 0 0.0.0.0:3000 LISTEN. docker ps shows no container binding 3000 because the run aborted.
Already attempted
Stopped a local test service on port 3000 and re-ran docker run; the container then started successfully. No changes were made to firewall or iptables rules.
Diagnostic steps
- Run sudo ss -lntp | grep :3000 (or sudo lsof -iTCP:3000 -sTCP:LISTEN) to identify the process and PID listening on the host port.
- What the result means: 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.
- List Docker containers and their published ports: docker ps --format '{{.ID}} {{.Names}} {{.Ports}}'.
- What the result means: 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.
- 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.
- What the result means: 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.
- 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.
- What the result means: 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.
Confirmed fixes
No fix has been independently verified for this scenario. Treat the causes below as diagnostic hypotheses.
Question
What steps will reliably identify which process owns the port, whether Docker or host service is responsible, and how to map or free the port safely in production without disrupting unrelated services?
Verified community troubleshooting
No answers yet..
Incident analysis
Most likely causes
Summary
Suggested Fixes
Continue troubleshooting
Related troubles
Matched from the title, description and tags
- Linux28% match
Ubuntu 22.04: Docker containers intermittently lose DNS after host switches to systemd-resolved stub resolver during network changes
Solved1 answer - Linux27% match
Docker containers see config file permission change after editor 'atomic save' — bind-mounted file temporarily unreadable until container restart
Open0 answers - Linux25% match
Ubuntu 22.04 laptop: Docker containers lose DNS resolution after suspend/resume (systemd-resolved stub resolver conflict)
Open0 answers - Linux25% match
Docker containers lose DNS after host switched to systemd-resolved stub resolver on Ubuntu 22.04
Solved1 answer - Cloud Computing25% match
Docker image pulls fail with 'no space left on device' though df shows plenty of disk — overlayfs inode exhaustion on Ubuntu 22.04
Open1 answer