Home › DevOps › Docker Bind: Address Already in Use — Fix It in 60 Seconds
Beginner 3 min · December 06, 2026

Docker Bind: Address Already in Use — Fix It in 60 Seconds

Docker bind: address already in use error? Find the process hogging the port, kill it safely, and prevent it from ever breaking your deploy again.

N
Naren Founder & Principal Engineer

20+ years shipping production infrastructure and CI/CD at scale. Lessons pulled from things that broke in production.

Follow
✓ Production
production tested
December 06, 2026
last updated
2,151
articles · all by Naren
Before you start⏱ 18 min
  • ✓Basic familiarity with running Docker containers (docker run, docker ps)
  • ✓Access to a terminal on the host machine
  • ✓Understanding of what a TCP port is (port 80, 443, 8080)
 ● Production Incident 🔎 Debug Guide ⚙ Triage Commands
⚡Quick Answer

Run sudo lsof -i :8080 (or sudo ss -tulpn | grep 8080) to find the process holding the port, then either stop that process or change your container's host port mapping with -p 8081:80. If it's a stale container, docker ps -a and docker rm -f clears it.

✦ Definition~90s read
What is Docker bind?

The 'bind: address already in use' error happens when Docker tries to map a container port to a host port that another process (or another container) is already listening on. The kernel refuses the bind because only one process can own a given port on a given IP address at a time.

★
Imagine a hotel with one phone line per room number.
Plain-English First

Imagine a hotel with one phone line per room number. If room 8080 is already occupied by a guest making a call, the front desk can't assign that same line to a new guest — the switchboard physically can't route two calls to one line. Docker is the front desk, the port is the phone line, and the error is the switchboard saying 'that line is busy.' You either evict the current guest or give the new one a different room number.

Every Docker user hits `bind: address already in use` within their first week, and most of them fix it wrong — they reboot the machine. That's like burning down the hotel because one phone line is busy. The error is not a Docker bug. It's the Linux kernel doing exactly what it's supposed to do: enforcing that one port belongs to one listener. The confusion comes from Docker's port publishing layer, which sits between your container and the host network and makes it non-obvious who actually owns the port. Once you see that layer clearly, the fix takes ten seconds. By the end of this article you'll be able to identify the exact process holding any port, distinguish between a stale container and a host service, choose between killing the offender and remapping the port, and set up your compose files so this never bites you in CI again.

What 'Bind' Actually Means (And Why the Kernel Cares)

Before you can fix the error, you need to know what a bind is. When a program wants to receive traffic on a port, it calls the bind() syscall, which tells the kernel: 'route packets arriving on this IP and port to me.' The kernel keeps a table of these claims. Only one process can hold a given (IP, port, protocol) tuple at a time. Docker's -p 8080:80 flag doesn't magically create a new port — it asks the kernel to bind host port 8080 and forward traffic to the container's port 80. If anything else already holds 8080, the kernel returns EADDRINUSE, and Docker surfaces it as bind: address already in use. That's the whole story. No Docker daemon bug, no networking wizardry — just a kernel table with a conflict.

inspect-port-ownership.shBASH
1
2
3
4
5
6
7
8
9
10
# io.thecodeforge — DevOps tutorial
# Show every listener on the host, with PID and process name.
# -t = TCP, -u = UDP, -l = listening, -p = show process, -n = numeric ports
sudo ss -tulpn

# Narrow to a single port (replace 8080 with yours)
sudo ss -tulpn | grep ':8080'

# Alternative if ss is unavailable (older distros)
sudo lsof -i :8080 -P -n
Output
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
tcp LISTEN 0 128 0.0.0.0:8080 0.0.0.0:* users:(("docker-proxy",pid=4821,fd=4))
tcp LISTEN 0 128 127.0.0.1:8080 0.0.0.0:* users:(("checkout-sidecar",pid=9134,fd=3))
🔥Senior Shortcut:
docker-proxy appearing in ss output is normal — it's Docker's userland proxy forwarding traffic. The real conflict is the other line. If you only see docker-proxy, the port is held by a container; if you see a named binary, it's a host process.

The Two Flavors of the Error (And How to Tell Them Apart)

Not all address already in use errors are the same. There are two distinct causes, and the fix differs. Flavor one: a host process (nginx, a sidecar, a dev server you forgot) holds the port. Flavor two: a Docker container — often a stale one from a previous docker run — holds the port. The error text is nearly identical, but the diagnostic path diverges. For flavor one, ss shows a real binary name. For flavor two, ss shows docker-proxy and docker ps shows a running container. Mixing these up wastes time: people docker rm -f containers that don't exist while nginx laughs at them from the host.

classify-port-conflict.shBASH
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# io.thecodeforge — DevOps tutorial
# Step 1: who owns the port?
PORT=8080
sudo ss -tulpn | grep ":$PORT"

# Step 2: is it a Docker container?
docker ps --format 'table {{.ID}}\t{{.Names}}\t{{.Ports}}' | grep ":$PORT"

# Step 3: if a container owns it, inspect and stop it
docker ps --filter "publish=$PORT" --format '{{.ID}} {{.Names}}'
# Then: docker stop <id>  (or docker rm -f <id> if it's stale)

# Step 4: if a host process owns it, decide: kill or remap
# Kill:  sudo kill <PID>
# Remap: docker run -p 8081:80 myapp:latest
Output
$ sudo ss -tulpn | grep ':8080'
tcp LISTEN 0 128 0.0.0.0:8080 0.0.0.0:* users:(("docker-proxy",pid=4821,fd=4))
$ docker ps --format 'table {{.ID}}\t{{.Names}}\t{{.Ports}}' | grep ':8080'
a1b2c3d4e5f6 checkout-api 0.0.0.0:8080->8080/tcp
# Conclusion: a container named checkout-api owns the port.
Port Conflict Classification
Ifss shows docker-proxy AND docker ps shows a container on that port
→
UseContainer conflict — docker stop <id> or docker rm -f <id>
Ifss shows a named binary (nginx, node, python) and no container
→
UseHost process conflict — sudo systemctl stop <service> or sudo kill <PID>
Ifss shows both docker-proxy and a host binary on the same port
→
UseDual bind — one is on 0.0.0.0, the other on 127.0.0.1. Stop the host binary or remap the container.

The Fastest Fix: Remap the Host Port

When you don't care which host port the container uses — and in dev you usually don't — the fastest fix is to remap. Change -p 8080:80 to -p 8081:80 and move on. The container's internal port stays 80; only the host side changes. This is the right move when the conflicting process is something you need (a local Postgres, a colleague's service, a system daemon). It's the wrong move in production, where the host port is part of your contract with the load balancer. Know which situation you're in before you reach for it.

remap-container-port.shBASH
1
2
3
4
5
6
7
8
9
10
11
12
13
# io.thecodeforge — DevOps tutorial
# Original command that failed:
# docker run -d --name checkout-api -p 8080:80 checkout-api:latest
# Error: bind: address already in use

# Fix: move the host side to 8081, keep the container side at 80
docker run -d --name checkout-api -p 8081:80 checkout-api:latest

# Verify the mapping
docker port checkout-api

# Hit it to confirm
docker run --rm --network host curlimages/curl -s http://localhost:8081/health
Output
$ docker port checkout-api
80/tcp -> 0.0.0.0:8081
$ docker run --rm --network host curlimages/curl -s http://localhost:8081/health
{"status":"ok"}
⚠ Production Trap:
Remapping in production breaks your load balancer target group, your health checks, and your firewall rules. If you're tempted to remap in prod, stop — find and kill the conflicting process instead.

The Correct Fix: Find and Kill the Offender

In production, the host port is part of your infrastructure contract. You don't remap — you find the process that stole the port and stop it. The sequence is always the same: identify the PID with ss or lsof, confirm what it is with ps, then stop it cleanly. The trap is killing the wrong thing. A docker-proxy PID is a child of the Docker daemon; killing it directly can leave the daemon in a confused state. Kill the container instead. A systemd-managed service should be stopped with systemctl stop, not kill -9, so its socket closes cleanly and doesn't linger in TIME_WAIT.

kill-port-offender.shBASH
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# io.thecodeforge — DevOps tutorial
PORT=8080

# 1. Find the PID holding the port
PID=$(sudo ss -tulpn | grep ":$PORT " | grep -oP 'pid=\K[0-9]+' | head -1)
echo "Port $PORT held by PID $PID"

# 2. Identify the process before killing it
ps -p "$PID" -o pid,comm,args

# 3. If it's a systemd service, stop it cleanly
# sudo systemctl stop <service-name>

# 4. If it's a stray process, send SIGTERM first (graceful)
sudo kill "$PID"

# 5. Wait for the socket to release, then verify
sleep 2
sudo ss -tulpn | grep ":$PORT" || echo "Port $PORT is free"
Output
$ ./kill-port-offender.sh
Port 8080 held by PID 9134
PID COMMAND COMMAND
9134 checkout-sidecar /usr/local/bin/checkout-sidecar --port 8080
Port 8080 is free
💡Never Do This:
sudo kill -9 on a docker-proxy PID. It orphans the container's network namespace and you'll need to restart the Docker daemon to recover. Stop the container with docker stop, not the proxy.

Stale Containers: The Most Common Beginner Trap

You ran docker run yesterday, forgot about it, and today your new container can't bind. docker ps shows nothing because the old container exited — but a container in Exited state still holds its port mapping until it's removed. This is the single most common cause of the error for beginners. The fix is two commands: docker ps -a to see everything including stopped containers, then docker rm -f <id> to remove the offender. Better: use --rm on every docker run in dev so containers clean themselves up when they exit.

clean-stale-containers.shBASH
1
2
3
4
5
6
7
8
9
# io.thecodeforge — DevOps tutorial
# Show ALL containers, including exited ones that still hold ports
docker ps -a --format 'table {{.ID}}\t{{.Names}}\t{{.Status}}\t{{.Ports}}'

# Remove any container (running or stopped) that maps the port
docker ps -a --filter "publish=8080" --format '{{.ID}}' | xargs -r docker rm -f

# Prevent the problem next time: --rm auto-deletes on exit
docker run --rm -d --name checkout-api -p 8080:80 checkout-api:latest
Output
$ docker ps -a --format 'table {{.ID}}\t{{.Names}}\t{{.Status}}\t{{.Ports}}'
CONTAINER ID NAMES STATUS PORTS
a1b2c3d4e5f6 checkout-api Exited (0) 2 hours ago 0.0.0.0:8080->8080/tcp
$ docker ps -a --filter "publish=8080" --format '{{.ID}}' | xargs -r docker rm -f
a1b2c3d4e5f6
# Port is now free.
⚠ The Classic Bug:
docker ps only shows running containers. If your port is held by an exited container, docker ps shows nothing and you'll waste 20 minutes. Always use docker ps -a when debugging port conflicts.

Docker Compose: Why 'down' Isn't Always Enough

With Compose, the error usually appears after a docker compose up following a previous run. docker compose down stops and removes containers, but if a container was started outside Compose (or a docker run snuck in), down won't touch it. The reliable sequence is: docker compose down --remove-orphans to clean up anything Compose knows about, then check docker ps -a for strays. Also watch for docker compose up without -d — it attaches to the terminal, and Ctrl+C sometimes leaves the container running depending on your Compose version.

docker-compose.ymlYAML
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# io.thecodeforge — DevOps tutorial
services:
  checkout-api:
    image: checkout-api:latest
    # Bind to a specific host IP, not 0.0.0.0, to reduce conflict surface
    ports:
      - "127.0.0.1:8080:8080"
    # Healthcheck so Compose knows when the app is actually ready
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
      interval: 10s
      timeout: 3s
      retries: 3
    restart: unless-stopped
Output
$ docker compose down --remove-orphans
[+] Running 2/2
✔ Container checkout-api-1 Removed
✔ Network checkout_default Removed
$ docker compose up -d
[+] Running 2/2
✔ Network checkout_default Created
✔ Container checkout-api-1 Started
Compose Port Conflict Recovery
Ifdocker compose up fails with bind error after a previous run
→
Usedocker compose down --remove-orphans then docker compose up -d
Ifdown succeeds but up still fails
→
Usedocker ps -a — a container started outside Compose is holding the port; docker rm -f it
IfError persists with no containers visible
→
UseHost process conflict — sudo ss -tulpn | grep :<port> and stop the host service

Binding to 127.0.0.1 vs 0.0.0.0: The Subtle Conflict

Here's a case that confuses even experienced devs. A process bound to 127.0.0.1:8080 and a container trying to bind 0.0.0.0:8080 will conflict — even though they look like different addresses. Why? 0.0.0.0 means 'all interfaces,' which includes 127.0.0.1. The kernel won't let two listeners overlap. The error message will say bind: address already in use on 0.0.0.0:8080, and ss will show the host process on 127.0.0.1:8080. The fix is either to stop the host process or to bind the container to a specific IP: -p 127.0.0.1:8080:8080 — but that only works if the host process is on a different IP, which it usually isn't.

diagnose-ip-conflict.shBASH
1
2
3
4
5
6
7
8
9
10
11
12
13
# io.thecodeforge — DevOps tutorial
# Show the exact bind address for every listener on 8080
sudo ss -tulpn 'sport = :8080'

# Example output showing the overlap:
# tcp LISTEN 0 128 127.0.0.1:8080 0.0.0.0:* users:(("node",pid=1234))
# Docker wants 0.0.0.0:8080 — conflict, because 0.0.0.0 includes 127.0.0.1

# Fix A: stop the host process
sudo kill 1234

# Fix B: bind container to a different host IP (only if host has multiple IPs)
docker run -d -p 192.168.1.50:8080:8080 checkout-api:latest
Output
$ sudo ss -tulpn 'sport = :8080'
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
tcp LISTEN 0 128 127.0.0.1:8080 0.0.0.0:* users:(("node",pid=1234,fd=20))
# Docker's bind to 0.0.0.0:8080 fails because 0.0.0.0 overlaps 127.0.0.1.
🔥Interview Gold:
0.0.0.0 is a wildcard, not an address. It means 'every interface on this host,' which includes loopback. That's why a 127.0.0.1 listener blocks a 0.0.0.0 bind — they overlap.

Preventing It: Pre-Flight Checks and Port Contracts

The best fix is the one you never have to run. In CI and deploy pipelines, add a pre-flight check that fails fast with a clear message before Docker even tries to bind. In dev, standardize on a port range per project (e.g., 8000–8099 for project A, 8100–8199 for project B) so two projects never collide. In Compose, use 127.0.0.1: prefixes for services that don't need external access — it shrinks the conflict surface and is a security win too. These three habits eliminate 90% of bind errors before they happen.

preflight-port-check.shBASH
1
2
3
4
5
6
7
8
9
10
11
12
# io.thecodeforge — DevOps tutorial
# Fail the deploy early if the port is already claimed.
set -euo pipefail
PORT="${1:-8080}"

if sudo ss -tulpn | grep -q ":$PORT "; then
  echo "FATAL: port $PORT is already in use:" >&2
  sudo ss -tulpn | grep ":$PORT " >&2
  exit 1
fi

echo "Port $PORT is free — proceeding with deploy."
Output
$ ./preflight-port-check.sh 8080
FATAL: port 8080 is already in use:
tcp LISTEN 0 128 0.0.0.0:8080 0.0.0.0:* users:(("docker-proxy",pid=4821,fd=4))
$ echo $?
1
$ ./preflight-port-check.sh 9090
Port 9090 is free — proceeding with deploy.
💡Senior Shortcut:
In Compose, use ports: ["127.0.0.1:8080:8080"] for internal services. It binds only to loopback, so it can't conflict with a 0.0.0.0 listener and it's not exposed to the network — two wins for one line.
● Production incidentPOST-MORTEMseverity: high

The Port That Broke the Blue-Green Deploy

Symptom
A blue-green deploy of a checkout API failed at 2am. The new green container exited immediately with bind: address already in use on port 8080, but docker ps showed only the blue container running.
Assumption
The team assumed a zombie container from a previous failed deploy was still holding the port and started hunting through docker ps -a.
Root cause
The previous deploy's health-check sidecar — a tiny Go binary running as a systemd unit on the host — was still bound to 127.0.0.1:8080 because its stop script had a race condition and exited before the socket closed. Docker's port publishing tried to bind 0.0.0.0:8080, which conflicts with any listener on the same port regardless of interface.
Fix
sudo ss -tulpn | grep :8080 revealed the sidecar PID. sudo systemctl stop checkout-healthcheck && sudo systemctl disable checkout-healthcheck freed the port. The deploy pipeline was patched to run ss -tulpn | grep :8080 as a pre-flight gate and fail fast with a clear message.
Key lesson
  • Docker only owns the ports it publishes — anything else on the host can steal them, and docker ps will never show you the thief.
Production debug guideSystematic recovery paths for the failure modes engineers actually hit.4 entries
Symptom · 01
Error response from daemon: driver failed programming external connectivity ... bind: address already in use on deploy
→
Fix
1. Run sudo ss -tulpn | grep :<PORT> to identify the PID and process name. 2. If it's docker-proxy, run docker ps --filter publish=<PORT> to find the container, then docker stop <id>. 3. If it's a named host binary, run sudo systemctl stop <service> or sudo kill <PID>. 4. Re-run the deploy.
Symptom · 02
Port conflict only after a blue-green or rolling deploy, with no visible container
→
Fix
1. Check for host-level sidecars: sudo ss -tulpn | grep :<PORT>. 2. Check systemd units: systemctl list-units --type=service | grep -i <app>. 3. Stop the orphaned sidecar with sudo systemctl stop <unit>. 4. Add a pre-flight ss check to the deploy pipeline.
Symptom · 03
docker compose up fails with bind error after a previous run
→
Fix
1. docker compose down --remove-orphans. 2. docker ps -a --filter publish=<PORT> to find strays. 3. docker rm -f <id> for any container outside the Compose project. 4. docker compose up -d.
Symptom · 04
Error mentions 0.0.0.0:<port> but ss shows a 127.0.0.1:<port> listener
→
Fix
1. Confirm overlap: sudo ss -tulpn 'sport = :<PORT>'. 2. Stop the loopback listener (sudo kill <PID> or systemctl stop). 3. If the host process must stay, bind the container to a different host IP: -p <HOST_IP>:<PORT>:<CONTAINER_PORT>.
★ Docker bind: address already in use Triage Cheat SheetFirst-response commands for when things go wrong — copy-paste ready.
`bind: address already in use` on `docker run`−
Immediate action
Identify which process holds the port before touching anything.
Commands
sudo ss -tulpn | grep :8080
docker ps -a --filter publish=8080
Fix now
If container: docker rm -f <id>. If host process: sudo kill <PID> or sudo systemctl stop <service>.
Error after `docker compose up` following a previous run+
Immediate action
Clean up the Compose project and any orphans.
Commands
docker compose down --remove-orphans
docker ps -a --filter publish=8080
Fix now
docker compose up -d after confirming the port is free with ss.
Port 80/443 conflict with no container visible+
Immediate action
Check for host nginx/apache binding the port.
Commands
sudo lsof -i :80 -P -n
sudo systemctl status nginx
Fix now
sudo systemctl stop nginx or reconfigure nginx to proxy to the container instead of binding the port itself.
`0.0.0.0:<port>` conflict while `ss` shows `127.0.0.1:<port>`+
Immediate action
Confirm the loopback listener is the blocker.
Commands
sudo ss -tulpn 'sport = :8080'
ps -p <PID> -o pid,comm,args
Fix now
Stop the loopback listener, or bind the container to a specific non-loopback host IP with -p <IP>:<PORT>:<PORT>.
ApproachWhen to UseRisk
Remap host port (-p 8081:80)Dev, local testing, non-contractual portsBreaks load balancer / firewall rules in prod
Kill the conflicting processProduction, contractual portsKilling the wrong PID can destabilize the host
docker rm -f stale containerExited containers holding portsData loss if the container had unnamed volumes
docker compose down --remove-orphansCompose-managed stacksDoesn't touch containers started outside Compose
Bind to 127.0.0.1Internal services, devNot reachable from other hosts — intentional
⚙ Quick Reference
8 commands from this guide
FileCommand / CodePurpose
inspect-port-ownership.shsudo ss -tulpnWhat 'Bind' Actually Means (And Why the Kernel Cares)
classify-port-conflict.shPORT=8080The Two Flavors of the Error (And How to Tell Them Apart)
remap-container-port.shdocker run -d --name checkout-api -p 8081:80 checkout-api:latestThe Fastest Fix
kill-port-offender.shPORT=8080The Correct Fix
clean-stale-containers.shdocker ps -a --format 'table {{.ID}}\t{{.Names}}\t{{.Status}}\t{{.Ports}}'Stale Containers
docker-compose.ymlservices:Docker Compose
diagnose-ip-conflict.shsudo ss -tulpn 'sport = :8080'Binding to 127.0.0.1 vs 0.0.0.0
preflight-port-check.shset -euo pipefailPreventing It

Key takeaways

1
docker ps only shows running containers
always use docker ps -a when debugging port conflicts, because exited containers still hold their port mappings.
2
0.0.0.0 is a wildcard that includes 127.0.0.1, so a loopback listener blocks a wildcard bind
this is the conflict that confuses even experienced devs.
3
In production, never remap a host port to 'fix' the error
the port is part of your contract with the load balancer. Find and stop the offending process instead.
4
The fastest permanent fix is a pre-flight ss -tulpn | grep :<port> check in your deploy pipeline that fails fast with a clear message before Docker even tries to bind.
INTERVIEW PREP · PRACTICE MODE

Interview Questions on This Topic

Q01SENIOR
Why does a process bound to `127.0.0.1:8080` block a Docker container tr...
Q02SENIOR
When would you remap a host port versus kill the conflicting process in ...
Q03SENIOR
A deploy fails with `bind: address already in use` but `docker ps` shows...
Q04JUNIOR
What does the `-p 8080:80` flag actually do at the kernel level?
Q05SENIOR
You're debugging a blue-green deploy where the green container can't bin...
Q06SENIOR
How would you design a multi-tenant deployment platform so port conflict...
Q01 of 06SENIOR

Why does a process bound to `127.0.0.1:8080` block a Docker container trying to bind `0.0.0.0:8080`?

ANSWER
0.0.0.0 is a wildcard meaning 'all interfaces,' which includes loopback. The kernel treats the two binds as overlapping, so the second one fails with EADDRINUSE. The fix is to stop the loopback listener or bind the container to a specific non-loopback IP.
FAQ · 4 QUESTIONS

Frequently Asked Questions

01
How do I fix 'bind: address already in use' in Docker?
02
What's the difference between `docker ps` and `docker ps -a` for port conflicts?
03
How do I find which process is using a port on Linux?
04
Why does Docker say 'address already in use' when nothing is running on that port?
RESOURCES

Keep going

AutoSys Full Course for Beginners▶
WatchAutoSys Full Course for BeginnersJIL, job statuses, monitoring and failed jobs, start to finish.Watch on YouTube →
ReadThe complete DevOps guideOne deep guide that walks the whole DevOps track in order.Start reading →
Q
PracticeDevOps Interview QuestionsReal interview questions with answers, by topic.Practice now →
N
Naren Founder & Principal Engineer

20+ years shipping production infrastructure and CI/CD at scale. Lessons pulled from things that broke in production.

Follow
✓ Verified
production tested
December 06, 2026
last updated
2,151
articles · all by Naren
🔥

That's Docker. Mark it forged?

3 min read · try the examples if you haven't

←
Previous
Git Permission denied (publickey) Fix
27 / 27 · Docker