Coding Agents & Terminal · recorded 2026-08-31 · applies to 1 tool(s) ✓ Verified

Problem: docker says "Conflict. The container name /xxx is already in use" —— Trove problem library

Verified 2026-08-31container name conflict — `docker rm -f` the old container holding the name (exited ones too), then rerun the original command.

Quick fix

# One shot: remove the name holder (works even when exited), then rerun
docker rm -f repro-conflict && docker run -d --name repro-conflict alpine sleep 60

What you will run into

Running docker run --name xxx ... a second time with the same name fails with docker: Error response from daemon: Conflict. The container name "/xxx" is already in use by container "...".

Most common in script re-runs, CI retries and tutorial walkthroughs — container names are globally unique per daemon: docker stop does not free the name, and plain docker ps (without -a) does not show the exited container, so it is easy to misread the name as free.

Why this happens

--name registers the name in the daemon's global name index at container create time. docker stop only moves the container to the exited state — the container object and its name still exist; only docker rm deletes the object and releases the name.

So "run the same command twice" collides. Compose does not hit this because it removes old containers before recreating them.

The container lifecycle is create → start → stop → rm: the name is claimed at create and released only at rm; stop does not release it.

The by container "<id>" part of the error identifies the current name holder — docker ps -a will always show it, because plain docker ps only lists running containers.

Deterministic takeaway: either docker rm -f the holder or use a different --name — there is no third option; "remove then create" is the idempotent standard for site docs

Step by step

1. Find the name holder — Must do

docker ps -a | grep <name>

Exited containers are hidden from plain docker ps; you need -a.

2. Remove it if it is useless — Must do

docker rm -f <name>   # running container: -f force; exited: plain rm is enough

3. Rename instead (keep the old container) — By scenario

docker rename <old> <new>        # or start the new one with a different --name

How to confirm it works

docker ps -a | grep <name> shows no same-name container; rerunning docker run --name <name> succeeds and prints a container id with no Conflict error.

Other environments

EnvironmentNote
Exited container holds the nameOnly visible with docker ps -a (reproduced: stop keeps the name)
Running container holds the namedocker rm -f, or stop then rm
ComposeNormally handled; if you see it, a hand-run container with the same name exists

Symptom

docker: Error response from daemon: Conflict. The container name "/repro-conflict" is already in use by container "49e3c7e4...". You have to remove (or rename) that container to be able to reuse that name.

Run 'docker run --help' for more information

Signature: the second docker run --name with the same name fails; the error carries the full Conflict. The container name "..." is already in use text and the holder container id.

Cause

Container names are a daemon-global unique resource, claimed at create and released only at rm; stop does not release it. Creating the same name again is a Conflict; docker ps only lists running containers, so "not visible" is easily misread as "name free".

Solution

  1. docker ps -a | grep <name> to find the holder;
  2. Useless → docker rm -f <name>; useful → docker rename or pick another name;
  3. In site docs remove before create (docker rm -f first) or add || true for idempotency.
Verification Evidence
  • Local reproduction (2026-08-31, WSL Ubuntu, docker 29.1.3, alpine:latest):
  • Chain A: docker run -d --name repro-conflict alpine sleep 60 succeeds (prints container id) → same command again → docker: Error response from daemon: Conflict. The container name "/repro-conflict" is already in use by container "49e3c7e4..." (exit 125);
  • Chain B: docker rm -f repro-conflict then the same command → succeeds.

Evidence details kept locally (2026-08-31)

Related canonicals

Read in order: precondition -> same root / same domain / related:

  • Related (similar errors, different cause):
  • Docker daemon unreachable (confirm the daemon is alive before hunting name conflicts)

Applicable tools (1)

This problem is linked from the tool pages below — reachable from either side.

docker

Source & evidence

Recorded Verified ✓ VerifiedApplies to 1 tool(s)
Entries contain locally measured or reviewable-source solutions; unmeasured items are explicitly labeled.

← Coding Agents & Terminal domain | Problem Catalog Experience | Facing another issue? Go to the Helpdesk