Troubleshooting guide
Docker "port is already allocated": how to fix it
Docker cannot publish a host port that something else holds. The holder is another container, a host process, or a stale leftover.
3 min read11 sectionsUpdated
On this page
# Which container publishes it?
docker ps --filter publish=8080 --format '{{.Names}} {{.Ports}}'
# Which host process holds it?
sudo lsof -nP -iTCP:8080 -sTCP:LISTEN
sudo ss -ltnp | grep ':8080'
# All Compose projects on this machine
docker compose lsFixes
Stop whichever container or service holds the port, or map another: -p 8081:80. In Compose, make the port configurable: "${APP_PORT:-8080}:80", so two checkouts can run side by side. Use docker compose down rather than stop when you are finished. If nothing holds the port and the error persists, restart the Docker daemon to clear stale state. For a service that does not need outside access, do not publish a port at all, and let containers talk over a Docker network.
Why this happens on servers
On production hosts the conflict is usually an orchestration issue. A blue-green script that starts a new container before stopping the old one cannot share a host port, so publish different host ports and switch a reverse proxy between them. On a developer machine, the conflict tends to come from a database installed natively and another copy started in Compose. Remove one, or change the host side of the mapping, and remember to update the application's connection string to the new port.
Catch it automatically
In production this usually shows up as a deployment where the new container cannot start while the old one still runs. Use a health-gated rollout and an uptime check after each deploy. Monitor the restart count with container monitoring.
Can two containers use the same internal port?
Yes. Only host port mappings must be unique.
Why does it say allocated when nothing is running?
A stale docker-proxy or a process outside Docker may hold it. Check with lsof or ss, or restart Docker.
How do I see all published ports?
Run docker ps and look at the Ports column.
Check it now, free
- Open port checker: Is a TCP port open, closed or filtered from the internet?
Related reading
- ERR_UNSAFE_PORT: how to fix it: Fix ERR_UNSAFE_PORT: Chrome blocks web requests to ports used by other protocols (SMTP, IRC, SIP). Move your service to a safe port or allow it locally.
- net::ERR_FAILED: how to fix it: Fix net::ERR_FAILED in Chrome and the console: CORS preflight failures, service workers, blocked requests, cache problems and extensions, step by step.
- ERR_TUNNEL_CONNECTION_FAILED: how to fix it: Fix ERR_TUNNEL_CONNECTION_FAILED: proxy servers refusing HTTPS tunnels, wrong proxy settings, VPN apps and corporate filters, step by step.
- Kubernetes readiness probe failed: how to fix it: Fix Kubernetes readiness and liveness probe failures: slow startup, wrong ports, overloaded health endpoints and dependency checks that cause cascading outages.
- ERR_CONTENT_DECODING_FAILED: how to fix it: Fix ERR_CONTENT_DECODING_FAILED: wrong Content-Encoding headers, double gzip compression, broken Brotli, PHP output buffering and proxies, with tests.
- ERR_PROXY_CONNECTION_FAILED: how to fix it: Fix ERR_PROXY_CONNECTION_FAILED ("No internet, there is something wrong with the proxy server"): remove stale proxies, fix PAC files and VPN leftovers.
Watch your own site and services with VitalRix
Uptime checks, APM, logs, real-user monitoring, alerts and status pages in one place. Every product has a free tier and no credit card is needed.