Port is already allocated

Docker Daemon ErrorNetwork ErrorCommonLast updated: June 28, 2026Tested on:Docker Engine v26.0Docker Compose v2.24June 2026

The host network port specified in the container binding is already being used by another process or container.

Port is already allocated Quick Fix⏱️ Est. Fix Time: 2 minutes

Usually happens because:

  • Host database or web server is currently active
  • Another running container maps to the same port
  • Zombie process did not release socket connection

🔍 Quick Checklist:

What is Port is already allocated?

This error occurs when you attempt to start a container with a host port mapping (e.g. -p 8080:80) but the specified host port (8080) is already occupied by a running service on your host machine (like an Apache/Nginx server, a local database, another active container, or a zombie process that did not release the socket).

Common Causes

  • Another container using the port: An active or orphaned container has already mapped the host port.
  • Host service using the port: A local server process running directly on the host machine is listening on the port (e.g. local PostgreSQL running on 5432).
  • Zombie process lock: A terminated process failed to release its socket binding, leaving the port locked.
CauseFrequency
Host service utilizing the port⭐⭐⭐⭐⭐
Another active docker container⭐⭐⭐⭐
Zombie process socket lock⭐⭐

Common Mistakes

  • Starting a local developer database server (like postgres or mysql) directly on the host machine while simultaneously trying to launch a container mapping to the same default database port.
  • Ignoring stopped containers that still hold proxy binding records.

How to Fix

1Map to a different host port: Modify the port mapping flag to use an available host port (e.g. change '-p 8080:80' to '-p 8081:80').
2Identify and terminate the blocking process: Use system network tools (like 'lsof' or 'netstat') to find the PID, and kill the process.
3Stop conflicting containers: Check running containers using 'docker ps' and stop the container that is using the target port.

Docker Operations & Verification

Locate which process or server is holding the socket path.

Finding Port Users Example
# Linux/macOS command to trace port 80
sudo lsof -i :80
# Outputs: PID 1234 (nginx)

# Terminate the process holding the port
sudo kill -9 1234

Platform Specific Fixes

Find and kill socket processes using netstat or ss on Linux.

Linux Config
# Identify socket PID
sudo ss -lptn 'sport = :8080'
# Terminate process
sudo kill -9 <PID>

Best Practices

  • Always run `docker compose down` instead of simply closing the terminal to ensure ports are fully released.
  • Implement port isolation strategies using custom Docker networks instead of binding all containers directly to the host network.

Frequently Asked Questions (FAQ)

Q: What does port is already allocated mean?

It means the port you are trying to publish on your host machine is already in use by another application or container.

Q: How do I find what process is using a port?

On Linux/macOS, use 'lsof -i :<port>'. On Windows, use 'netstat -ano | findstr :<port>' inside PowerShell.

Q: Can I share a port between two containers?

No. Two containers cannot bind to the exact same port on the host machine. You can, however, map them to different host ports (e.g., -p 8080:80 and -p 8081:80).

Q: Why do closed containers still block ports?

If a container is stopped but not removed, some network adapters can fail to clear proxy rules. Run 'docker system prune' or restart the Docker service to clear these locks.

Still having this problem?

Didn't solve your problem?

SuggestRequest Error