Deploy blocked: port is already allocated
Easy

Problem

You're rolling out a new build of the web frontend. The deploy script tried to start it on the host's port 8080 and bailed out:

docker: Error response from daemon: failed to set up container
networking: driver failed programming external connectivity on endpoint
web-new (…): Bind for 0.0.0.0:8080 failed: port is already allocated

The new container never started. Something is already holding 8080 on this host. Find what, and get the new frontend listening.

Initial setup

One container is already on the host:

  • web-old — a previous frontend build, nginx:alpine, up 3 days,
published on 0.0.0.0:8080->80/tcp.

You want to bring up web-new (also nginx:alpine) serving on the host.

Example interaction

$ docker run -d --name web-new -p 8080:80 nginx:alpine
docker: Error response from daemon: failed to set up container networking:
driver failed programming external connectivity on endpoint web-new (…):
Bind for 0.0.0.0:8080 failed: port is already allocated

Run 'docker run --help' for more information

$ docker ps --filter "publish=8080"
CONTAINER ID   IMAGE          STATUS        PORTS                    NAMES
a1b2c3d4e5f6   nginx:alpine   Up 3 days     0.0.0.0:8080->80/tcp     web-old

Acceptance

You've solved it when:

  • You've identified that web-old already holds host port 8080
(not a daemon bug, not the new container).
  • You've brought web-new up running — either by stopping/removing
web-old and starting web-new on 8080, or by publishing web-new on a different free host port.

Constraints

  • Tools: docker CLI only.
  • The fix must leave web-new in status == running.

Follow-up

  1. On a Linux host, which command tells you whether the holder is a
container's docker-proxy versus an unrelated host process?
  1. Why does docker container prune not free the port here?
Live session
Code
SavedNo commands yet