Pages

Topics

Tools

↑↓navigate↵openescclose
All guides

Docker: driver failed programming external connectivity on endpoint

The daemon could not set up the host side of a published port. Separate a bind conflict from missing iptables chains, then fix the right one.

~5 min readDocker
#docker#networking#iptables#ports
Bold white headline reading EXTERNAL CONNECTIVITY with a Docker container crate blocked at an amber iptables gate.

Introduction & Quick Summary

docker compose up brings up the database container and then fails on the web container:

code
Error response from daemon: driver failed programming external connectivity on endpoint shop-web-1 (3f9c1a7b2e4d): Error starting userland proxy: listen tcp4 0.0.0.0:8080: bind: address already in use

Quick answer: Docker could not set up the host side of the published port. Something already owns 8080, or the kernel rules that forward traffic into the container are missing. Find out which of the two you have before restarting anything.

bash
# which process holds the port (needs root for the pid column) sudo ss -tlnp 'sport = :8080' # containers that are stopped but still hold the port via docker-proxy docker ps -a --filter "publish=8080"

The full error is a chain of three parts, and the middle one is the part people skip:

  • driver failed programming external connectivity on endpoint NAME — the bridge driver was configuring the host side for that container.
  • Error starting userland proxy: listen tcp4 ... bind: address already in use — docker-proxy could not bind the host port.
  • iptables failed: ... No chain/target/match by that name — the DOCKER chain itself is gone.

Those two tails have different causes. A bind failure is a port conflict on the host. A missing chain means something flushed or reloaded the firewall rules Docker depends on, and restarting the container will keep failing until the daemon rebuilds them.

Core Mechanics, Signatures & Reproducible Setup

Reproduce the conflict deterministically:

docker network create repro 2>/dev/null || true docker run -d --name a -p 8080:80 nginx:alpine docker run --rm -p 8080:80 nginx:alpine # fails with the bind message docker rm -f a

Reproduce the missing-chain variant on a test host only, because it drops connectivity for every container:

sudo iptables -t nat -F DOCKER docker run --rm -p 8081:80 nginx:alpine # fails with "No chain/target/match" sudo systemctl restart docker # daemon rebuilds its chains
Message fragmentMeaningWho owns the fix
Error starting userland proxy: bind: address already in usehost port takenyou, by freeing or remapping the port
iptables failed: iptables --wait -t nat -A DOCKER ...DOCKER chain absentdaemon restart, then firewall configuration
No chain/target/match by that nametables or chains flusheddaemon restart plus a persistent firewall rule set
failed to set up container networkingbridge or veth missingnetwork recreate, CNI or kernel module check
listen tcp4 0.0.0.0:80: bind: permission deniedprivileged port in rootless modeip_unprivileged_port_start or a higher port
address already in use on [::]:8080IPv6 listener separate from IPv4bind both families or disable IPv6 publish

Key Comparison Table

Publish formHost interfaces boundTypical failureBetter when
-p 8080:80all interfaces, IPv4 and IPv6any local listener conflictsthe service must be public
-p 127.0.0.1:8080:80loopback onlyport used by another loopback servicereverse proxy runs on the host
-p 8080:80/tcp and -p 8080:80/udpone protocol eachUDP port still free, TCP takenboth protocols needed
network_mode: hosthost stack, no proxyevery host port is sharedperformance-critical local work
-p 127.0.0.1::80random high port on loopbackclient cannot find the portephemeral test runs

Fixes ranked by how much they change:

FixEffortEffect on the running systemNotes
Change the host portsecondsnonecompose file edit and recreate
Stop the conflicting processsecondsthat process goes downcheck first with ss
Remove a stale containersecondsits data may be lostdocker rm keeps volumes
Restart the Docker daemona minuteevery container restartsrebuilds missing chains
Set userland-proxy: falsedaemon configno docker-proxy, iptables onlydoes not fix a chain problem
Recreate the Docker networkseconds per networkcontainers detachfixes missing veth or bridge

Practical Edge Cases, Error Fixes & Deep Dive Code Examples

1. Reading the endpoint name to find the real container

endpoint shop-web-1 is the container, not the compose service alias. When several replicas publish the same port, only one gets it and the others fail:

bash
docker ps --format '{{.Names}}\t{{.Ports}}' | column -t docker compose ps --format 'table {{.Name}}\t{{.Publishers}}'

Compose with scale or a deploy.replicas block must not publish a fixed host port; put a reverse proxy in front and publish the port on the proxy only. The failure otherwise appears on the second and third replica and looks random.

2. Firewall reloads that delete Docker's chains

firewalld --reload, ufw reload, nft flush ruleset and cloud-init reruns can remove DOCKER, DOCKER-USER and DOCKER-ISOLATION-STAGE-*. Docker does not notice until the next container start:

bash
sudo iptables -t nat -L DOCKER -n | head sudo nft list ruleset | grep -i docker | head sudo systemctl restart docker

On hosts where the firewall is managed by a tool, add the Docker interface to its trusted zone instead of flushing:

bash
sudo firewall-cmd --permanent --zone=trusted --add-interface=docker0 sudo firewall-cmd --reload

The DOCKER-USER chain is the supported place for custom filtering; rules added directly to DOCKER are lost the moment the daemon restarts.

3. Stale containers and docker-proxy leftovers

bash
docker ps -a --filter status=exited --format '{{.ID}} {{.Names}} {{.Ports}}' docker compose down --remove-orphans

A container in Exited state does not hold a port, but a docker-proxy from a container that was killed with SIGKILL can linger for a moment, and a Compose project created with an older file keeps an old container around as an orphan. docker compose up --force-recreate then fails on the port the orphan still owns. --remove-orphans clears it.

4. Rootless Docker and ports below 1024

Rootless mode runs the daemon inside a user namespace, where net.ipv4.ip_unprivileged_port_start is 1024 by default:

docker run --rm -p 80:80 nginx:alpine # listen tcp4 0.0.0.0:80: bind: permission denied sysctl net.ipv4.ip_unprivileged_port_start # 1024 sudo sysctl -w net.ipv4.ip_unprivileged_port_start=80

Rootless users can set the value inside their own namespace without root on the host. Setting it to 0 allows every port for that user. The alternative is publishing 8080:80 and letting the host reverse proxy own port 80.

5. Docker Desktop, WSL2 and reserved Windows ranges

On Windows the failure often comes from Hyper-V reserving the port rather than from a listener:

Error starting userland proxy: listen tcp4 0.0.0.0:5000: bind: address already in use
powershell
netsh interface ipv4 show excludedportrange protocol=tcp

If the port sits in a reserved range, either pick a port outside it or reserve the port for Docker before the ranges are assigned:

powershell
net stop winnat netsh int ipv4 add excludedportrange protocol=tcp startport=5000 numberofports=1 net start winnat

WSL2 also keeps wslrelay processes that hold published ports for a few seconds after a container stops, which is why an immediate retry fails and a retry a minute later succeeds.

6. network_mode: host and custom networks

services: proxy: image: nginx:alpine network_mode: host ports: ["80:80"] # ignored, and misleading

With host networking the container shares the host stack, so ports is ignored and any host listener on 80 conflicts at process start rather than at container start. On macvlan or ipvlan networks the host cannot reach the container's IP unless a macvlan shim interface exists, and the publish flag does nothing because the container has its own IP. Validate a compose file before rebuilding the stack with the docker-compose viewer, and confirm the published endpoint answers with the cURL builder once it is up.

Common Compilation/Runtime Mistakes & Version Gotchas

Restarting the daemon first. It restarts every container on the host, including production ones, and it does not help when another process owns the port. Use ss first.

Adding privileged: true. Privileged mode does not grant a host port; the conflict is in the host network namespace, not in capabilities.

Setting iptables: false to silence the error. The container starts and then has no NAT, so published ports silently stop working and outbound container traffic loses source translation.

Assuming a container restart releases the port instantly. The kernel may keep TIME_WAIT sockets, and docker-proxy exits asynchronously. A short wait or a different host port is more reliable than looping docker compose up.

Publishing on all interfaces without meaning it. -p 8080:80 binds 0.0.0.0 and [::], so a database published for local development becomes reachable from the LAN. Bind 127.0.0.1 unless the service is meant to be public.

Version notes. Docker Engine 28 changed the default behaviour of published ports to route through the host rather than the userland proxy for some configurations, which alters the exact error text but not the causes. docker compose v2 parses deploy.replicas locally and now warns when replicas publish a fixed port, where v1 silently failed. On macOS, Docker Desktop's virtiofs and gRPC-FUSE file sharing do not affect ports; slow starts there are unrelated.

Reference material: Packet filtering and firewalls and Docker networking.

Official references

primary documentation

The Docker documentation that defines the behaviour this guide explains.

Try matching browser tools

All tools

Small utilities that fit Docker work — they run entirely in this browser tab, so nothing you paste leaves your device.

All Docker guides

More in Docker

All Docker guides

The guides filed next to this one in Docker, in library order.