How to Fix Port Is Already Allocated in Docker
Find the container or host process occupying a published Docker port and resolve the conflict without disrupting the wrong service.
Docker reports port is already allocated when another container or host process already owns the requested host address and port. Container ports can overlap; published host ports cannot overlap on the same address.
Find containers publishing the port
For host port 8080:
docker ps --format 'table {{.ID}}\t{{.Names}}\t{{.Ports}}'
docker ps --filter publish=8080
Inspect Compose projects as well:
docker compose ls
docker compose ps
An older project with a different directory name may still be running.
Find non-container listeners
sudo ss -ltnp 'sport = :8080'
sudo lsof -nP -iTCP:8080 -sTCP:LISTEN
Docker may use proxy or NAT rules, so compare this output with docker ps before stopping anything.
Change the correct mapping
In Compose, the left side is the host port:
ports:
- "8081:8080"
This publishes host port 8081 to container port 8080. If the service should not be public, bind it to loopback:
ports:
- "127.0.0.1:8081:8080"
Diagnose it with Rumus
Rumus is an AI-native terminal that can inspect both Docker and its Linux host in one workflow. It connects container state, logs, mounts, networking, and resource limits so you can fix the cause without blindly recreating workloads.
What Rumus can inspect
- Container state, exit codes, logs, and health checks
- Images, mounts, ports, users, and restart policies
- Host resources and Docker daemon context
Find what owns host port 8080. Check running and stopped containers, Compose
projects, host listeners, and the intended port mapping. Recommend the least
disruptive fix and do not stop containers or processes without approval.
Confirm the fix
Recreate the intended service, inspect its published mapping, and test it:
docker compose up -d
docker compose ps
curl -v http://127.0.0.1:8081/
Open the server in Rumus and let the AI agent inspect context, propose a plan, and ask before it runs changes.