How to Fix the Docker “Port Is Already Allocated” Error

You run docker compose up -d and instead of a running app you get an error that ends with “port is already allocated” or “address already in use”. This is one of the most common problems on a homelab mini PC, and it almost always has a simple cause: two things are trying to use the same port on your server. This guide shows how to find the culprit and fix it safely.

The commands below are standard Linux and Docker tools and apply to Ubuntu Server. I have not reproduced every variation of the error for this article, so read your own error message carefully and match it to the cases below.

What the error looks like

You will see one of these messages, depending on how you started the container:

Error response from daemon: driver failed programming external connectivity
on endpoint myapp: Bind for 0.0.0.0:8080 failed: port is already allocated

Error starting userland proxy: listen tcp4 0.0.0.0:8080: bind: address already in use

Both mean the same thing. Docker tried to publish a container port on a port of the host (your mini PC), and something there already owns it. A port can only be used by one program at a time, so the second one loses.

The number in the message (8080 in the example) is the host port in your Compose file. In a line such as "8080:80", the left number is the host port and the right number is the port inside the container. This is the left number you will change if you need to. If port mappings are new to you, see our Docker Compose beginner’s guide.

Step 1: Check whether another container uses the port

Start with Docker itself, because another container is the most common cause:

docker ps --format "table {{.Names}}\t{{.Ports}}"

Look for your port number in the list. If you find it, that container is the conflict. Also check stopped containers, since a leftover container from an earlier attempt can still hold on to its settings:

docker ps -a

Step 2: Check whether a program on the host uses the port

If no container matches, something outside Docker owns the port. Replace 8080 with your port:

sudo ss -tulpn | grep :8080

The last column shows the program name and process ID (PID). An alternative that many guides use is:

sudo lsof -i :8080

If the output shows docker-proxy, the port is being held by Docker for another container, so go back to Step 1. If you want more practice with commands like these, our Linux commands for homelab beginners guide covers the basics.

Step 3: Choose the safest fix

You have three options. Pick the one that matches what you found.

What you foundFix
Another container you still needChange the host port of the new container (for example "8081:80").
An old container you no longer needStop and remove it, then start the new one.
A system service on the hostStop or reconfigure the service, or change the host port of your container.

Changing the host port is the safest and quickest option, because it affects nothing else. In compose.yaml:

ports:
  - "8081:80"

Then apply it:

docker compose up -d

Open the app at the new port, such as http://192.168.1.50:8081. To remove an old container instead, use docker stop NAME and then docker rm NAME, or run docker compose down in the old project’s folder.

Avoid running kill -9 on a process you have not identified. Some processes on a server, such as the SSH service, are ones you want to keep. Always read the program name first.

Common homelab conflicts

  • Ports 80 and 443. Pi-hole’s web interface and a reverse proxy both want these. Move Pi-hole’s web port and let the proxy keep 80 and 443, as shown in our Nginx Proxy Manager and Pi-hole guide.
  • Port 53. On Ubuntu Server, a built-in service called systemd-resolved can already be using port 53, which blocks Pi-hole. The Pi-hole Docker guide explains how to deal with it.
  • The same port twice in one Compose file. Two services in the same file cannot both publish 8080. Give each a different host port.
  • The same stack started twice. If you ran the stack from two different folders, the first copy still holds the port. Run docker ps and stop the old one.

Prevent it next time

Keep a simple list of which host port belongs to which app, in a text file or notes app. Before deploying something new, run sudo ss -tulpn and check that your chosen port is free. If you use a visual tool like Portainer, its container list shows every published port in one place, which makes clashes easy to spot.

Frequently asked questions

Is “port is already allocated” the same as “address already in use”?

In practice, yes. Both mean the host port is taken. The first message usually comes from Docker noticing another container with that port, and the second from the operating system reporting that some program holds it.

I stopped the container but the error remains. Why?

Another process may still hold the port. Run sudo ss -tulpn | grep :PORT again. Also run docker ps -a to look for a half-created container left from a failed start, and remove it with docker rm.

Do I need to change the number inside the container?

No. Only change the host side (the left number). The container still uses its own internal port, so the app works the same.

Sources

Leave a Comment