Docker Port Is Already Allocated: Find the Process Using a Port
Fix Docker port is already allocated, address already in use, and EADDRINUSE errors on Windows and Linux without stopping the wrong process.
Article by Phạm Minh Thiện
Front-end developer working directly with Next.js, NestJS, Docker, Nginx, and Ubuntu VPS deployments.
Reviewed on 7/18/2026.
Table of contents
Docker reports port is already allocated when a host port in your Compose mapping is already owned by another container or process. Identify the owner first, then stop it only when you know it is no longer needed.
Read the port mapping correctly
In this mapping, 8080 is the host port and 3000 is the container port:
services:
api:
ports:
- "8080:3000"
The conflict is on 8080, not necessarily on port 3000 inside the container.
Check Docker containers first
docker ps --format "table {{.ID}}\t{{.Names}}\t{{.Ports}}"
docker ps -a --filter publish=8080
docker compose ls
If an old project owns the port, stop that project deliberately:
docker compose -p old-project down
Do not run a broad docker compose down from an unrelated directory.
Find a host process on Linux
sudo ss -ltnp 'sport = :8080'
sudo lsof -nP -iTCP:8080 -sTCP:LISTEN
Inspect the service before stopping it:
ps -fp <PID>
sudo systemctl status <service-name>
Find a host process on Windows
Get-NetTCPConnection -LocalPort 8080 -State Listen
Get-Process -Id <PID>
The legacy alternative is:
netstat -ano | findstr :8080
tasklist /FI "PID eq <PID>"
Only terminate a process after confirming what it belongs to.
Change the host port when both services are needed
services:
api:
ports:
- "8081:3000"
You can then open http://localhost:8081 while the application still listens on port 3000 inside its container.
Avoid unnecessary port publishing
If only another Compose service needs the API, remove ports and use the private network:
services:
api:
expose:
- "3000"
The reverse proxy can reach the service by its Compose name, such as api:3000.
Common causes
- A previous Compose project was left running.
- A local Node.js, Nginx, IIS, or database process uses the port.
- Two services publish the same host port.
- A development tool and Docker both use port 3000 or 8080.
- A restarting container immediately reclaims the port.
Five-minute checklist
- Read the host side of the mapping.
- Run
docker psand find published ports. - Check the operating system’s listening processes.
- Inspect the owner before stopping anything.
- Stop the correct project or choose another host port.
- Run
docker compose up -dand verify withdocker compose ps.
This is a resource ownership problem, not an instruction to kill every process that looks related to Docker.
Continue reading
Related articles
Docker Compose Ignores .env and PostgreSQL Says Password Authentication Failed
Understand .env, env_file, and environment in Docker Compose, inspect variables inside a container, and fix PostgreSQL passwords when a volume already exists.
Read article →Docker Compose in Production: Node.js, PostgreSQL, and Backups
Build a safer Docker Compose production stack for Node.js and PostgreSQL with health checks, private networks, volumes, secrets, log rotation, backups, and rollback.
Read article →What Is Docker? Images, Containers, Volumes, and Compose Explained
Learn how Docker works through images, containers, Dockerfiles, volumes, networks, and Compose with a practical Node.js example.
Read article →