docker "Error response from daemon: Conflict. The container name is already in use"
TL;DR: A stopped container with that name still exists. Remove it with docker rm [name], or run one-off containers with --rm so they delete themselves. In CI, add a cleanup step before the run so one failed build does not poison the next.
Error response from daemon: Conflict. The container name "/web" is already in use by container "a1b2c3d4e5f6"
Steps
- List it:
docker ps -a --filter name=[name]. Confirm the stale container and whether it is running or exited.
Expected: You see the conflicting container and its state.
- If it is exited and disposable, remove it and rerun:
docker rm [name]
Expected: The next docker run --name [name] starts clean.
- If it is running and should not be, stop it first, then remove it. If it should be running, you have two things fighting over one name; rename one of them.
Expected: The name is free, or the real owner is identified.
- Prevent recurrence for one-off runs: add
--rm so finished containers delete themselves.
Expected: No stale containers accumulate between runs.
- In CI, add a pre-step that removes any container with the job's name, or generate a unique name per run from the build id.
Expected: Name conflicts stop flaking the pipeline.
- Compose users:
docker compose down removes the project's containers. Conflicts across compose projects mean two projects share a name; give them distinct project names with -p.
Expected: Clean slate, no cross-project collision.
Use this when
docker run --name X fails with the Conflict message
Not for this skill when
- The error is
port is already allocated. That is a port conflict, same family but a different resource - The error is
unable to delete ... image is being used. That is an image reference conflict, not a name - The daemon is down. Nothing runs at all
Variant phrasings
Conflict. The container name "/name" is already in use by container "abc123"
The full form of the error with both names shown.
Why it happens
Container names are unique per daemon, and stopped containers keep their names until removed. A crashed or interrupted run leaves the name claimed, so the next identical run collides with the leftover of the last one.
Edge cases
--rm and --name work fine together; the container is removed when it exitsdocker rm -f handles stuck containers that ignore a plain stop- Two compose projects in directories with the same name share a default project name and will fight;
-p fixes it permanently
Provenance
Resolved from the public thread: https://vectle.com/posts/pst_vEqb8Blbe0xtYwdVVXVgQQ