Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Servers, nginx and Docker

A container cannot join a Docker network that still holds an endpoint with its name

Your error

Error response from daemon: endpoint with name web already exists in network mynet2 more lines it can show

Fix it fast

Most common cause, 1 of 2

A stale endpoint survived after its container was gone

Force-disconnect the name from the network.

Fix
docker network disconnect -f mynet web
docker compose up -d
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

"endpoint with name web already exists in network mynet" means the network already holds an endpoint named after the container. Either a stale endpoint outlived an unclean daemon stop, or a script connects a container that is already attached. Delete the stale one with docker network disconnect -f, or skip the repeated connect (Docker Engine 28 and 29).

  • Applies to Docker Engine 29, Docker Engine 28, Docker Compose v2+
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

Find out whether a container with the name from the error still exists, and if it does, which networks it already belongs to. No container at all points to a leftover endpoint; a running container that already lists the network points to a second connect.

Run this first
docker ps -a --filter name=web --format '{{.Names}}  {{.Status}}'
docker inspect --format '{{json .NetworkSettings.Networks}}' web

Then find the line you see in this list and open its fix:

  1. 1A stale endpoint survived after its container was gonedocker ps -a lists no container with that name, often right after a daemon crash, a killed dockerd or a host that lost power
  2. 2The running container is being connected to a network it already joineddocker inspect shows the network already present for a running container, and the error comes from a docker network connect line in a deploy script or hook

What does the error look like?

  • Error response from daemon: endpoint with name web already exists in network mynet
  • Error response from daemon: endpoint with name db already exists in network myproject_default
  • Error response from daemon: service endpoint with name web already exists

Cause 1 of 2

A stale endpoint survived after its container was gone

You seedocker ps -a lists no container with that name, often right after a daemon crash, a killed dockerd or a host that lost power

Check

The error appears because the network refuses a second endpoint with a name it already has, and endpoints take the container's name. When dockerd stops without a clean shutdown, it can leave network state behind for a container that no longer exists, and every new container with the same name then trips the check. Older engines printed the same refusal as 'service endpoint with name ... already exists'.

Check
docker ps -a --filter name=web
docker network ls

Fix

Force-disconnect the name from the network. When -f is given and no container of that name exists, the daemon looks the endpoint up by name in that network and deletes it.

Fix
docker network disconnect -f mynet web
docker compose up -d

Verify

The container starts and shows the network in its settings.

Verify
docker inspect --format '{{json .NetworkSettings.Networks}}' web

Confirmed by github.com

Did this fix it?

Cause 2 of 2

The running container is being connected to a network it already joined

You seedocker inspect shows the network already present for a running container, and the error comes from a docker network connect line in a deploy script or hook

Check

For a running container, docker network connect always asks the network for a new endpoint named after the container. If the container joined that network earlier, through docker run --network, a Compose networks entry or an earlier run of the same script, the name is taken and the daemon answers with this error.

Check
docker inspect --format '{{json .NetworkSettings.Networks}}' web
grep -rn "docker network connect" scripts/ .github/ 2>/dev/null

Fix

Make the connect step idempotent: attach only when the network is missing from the container's settings, or declare the network in Compose and drop the manual connect.

Fix
if ! docker inspect --format '{{json .NetworkSettings.Networks}}' web | grep -q '"mynet"'; then
  docker network connect mynet web
fi

Verify

Running the script twice in a row finishes without the error, and mynet appears once in the container's networks.

Verify
docker inspect --format '{{range $name, $net := .NetworkSettings.Networks}}{{$name}} {{end}}' web

Confirmed by github.com

Did this fix it?

How do I stop it coming back?

  • Stop containers and the Docker service cleanly before host maintenance or a reboot, so endpoints are released instead of left behind.
  • Guard every docker network connect in scripts with a check of the container's current networks.
  • Declare networks in compose.yaml instead of connecting containers by hand after they start.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine on the same stack: TaxiDex, Dispatch Pro.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.