Australian cloud for business software — built and run in Sydney since 2002

NetLeverage
NetLeverage

Docker "Conflict. The container name "/web" is already in use by container": find the holder, then rename it, remove it or choose another name

Technical article
Troubleshooting

About this article: This article is reviewed against the cited sources. This is source research, not lab validation. Check the stated versions and your own requirements before making changes.

When docker run or Compose stops with Conflict. The container name "/web" is already in use by container "...", another container already holds that name. The name belongs to that container whether it is running or stopped, and docker ps without -a hides stopped ones. List the holder, read what it is, and then rename it, remove it or choose another name. Removing is the one step for which Docker's page gives no way to undo it.

What the message means

In moby v27.3.1, the Docker daemon reserves a container's name when the container is created. If the name is reserved already, the daemon returns this wording: "Conflict. The container name %q is already in use by container %q. You have to remove (or rename) that container to be able to reuse that name." The first value is the name with a slash in front, and the second is the full ID of the container that holds it.

Docker's docker container ls page says the default listing shows "just running" containers and that -a, --all shows all. So a container that exited yesterday is invisible to a plain docker ps and still owns the name today. A container that was only created, never started, is listed with the status created, which the same page names among the status values.

Docker's run page shows --rm as "Automatically remove the container and its associated anonymous volumes when it exits", which is why scripts that use it do not hit this message after a normal exit.

Likely causes

Cause What you see How to confirm
A previous run exited and was not removed docker ps is empty, the conflict persists docker ps -a lists a container with status Exited
The same script or service is already running A container with status Up and that name docker ps lists it
A failed start left a created container Status Created docker ps -a shows Created; that a failed start can leave one is our reading, not stated on Docker's pages
Two Compose projects set the same container_name The second project's up conflicts container_name appears in both compose files
A filter showed a similar name The list holds web-2 but not web Read the NAMES column for the exact name

Prove the cause before changing anything

All of these only read.

1. Take the name and ID from the message. The name starts with a slash; the container ID is quoted at the end.

2. List every container with that name, running or not.

docker ps -a --filter name=web

Docker's page says the name filter "matches on all or part of a container's name", so the list can include web-2 or myweb. Find the row whose NAMES value is exactly web and whose CONTAINER ID starts the same as the ID in the message. The listing's columns include CONTAINER ID, IMAGE, COMMAND, CREATED, STATUS, PORTS and NAMES.

3. Read what the container is. Use the ID, not the name, so you cannot select the wrong one. The example ID below is made up; take the real one from your listing:

docker inspect 9c1f3a7b2e64

Look at the image, the creation time and the state. A good sign that it is stale is a creation time earlier than your latest deployment and a status of Exited.

4. Check for a restart policy. Docker's restart page says that a restart policy only takes effect after a container starts successfully, that always restarts a container that stops, and that a manually stopped one is restarted "only when Docker daemon restarts or the container itself is manually restarted". A container that returns after a daemon restart is under one.

5. For Compose, check container_name. Docker's services page says container_name "specifies a custom container name, rather than a name generated by default" and that Compose "does not scale a service beyond one container" when it is set. Search the compose files for it:

grep -rn container_name .

Fix

Choose by what the holder is. Renaming keeps everything and is the first choice.

Rename the holder

First save the current state:

docker inspect 9c1f3a7b2e64 > web-before.json

Risk: the next command renames an existing container. Anything that finds it by the name web, such as a script, a link or a monitoring check, stops finding it until the name is restored.

Rename it, using its ID:

docker rename 9c1f3a7b2e64 web-old-2026-12-02

Docker's page says docker rename renames a container, with the form docker container rename CONTAINER NEW_NAME.

To undo it, only while no other container holds the name web: first check with docker ps -a --filter name=web, and if a new container named web exists, rename that one first to another free name, because the rename fails with the same Conflict message while the name is held. Then rename the old container back to the name saved in web-before.json and list it.

docker rename 9c1f3a7b2e64 web
docker ps -a --filter name=web

Remove the holder

Remove only a container whose contents you do not need. Stopped containers from old runs are the usual case.

First save the current state, including what the container logged:

docker inspect 9c1f3a7b2e64 > web-before.json
docker logs 9c1f3a7b2e64 > web-logs-before.txt

Risk: the next command deletes the container 9c1f3a7b2e64 and its writable layer. Docker's page gives no way to undo it. The saved files record how it was configured and what it logged, not its file contents. Anonymous volumes are removed only with -v, which this command leaves out. Do not use -f: Docker's page says it removes a running container with SIGKILL.

Step 3 above has selected and shown the exact container. Remove it by ID:

docker rm 9c1f3a7b2e64

Docker's page describes docker rm as "Remove one or more containers".

To back out: there is none for the container. To recreate its configuration, read the image and options from web-before.json and start a new container from the image, which needs the image still to be available.

Choose another name in the compose file

Where the holder is a valid running service, the name in your script or compose file is the fault. The remedy is a different name there. A changed --name in a script follows the same save-first copy (cp -p of the script), warning and undo as the compose edit below.

First save the current state:

cp -p compose.yaml compose.yaml.2026-12-02

Risk: the next edit changes or removes the container_name line of the service. Anything that finds the container by its old name, such as a script or a monitoring check, stops finding it, and the next docker compose up creates a container under the new name.

Edit compose.yaml: give the service a different container_name, or delete the line so that Compose generates the name.

To undo it: copy the saved file back.

cp -p compose.yaml.2026-12-02 compose.yaml

Example (illustrative): On docker01, a nightly script runs docker run -d --name web registry.example.com/app:1.4. Today it ends with Conflict. The container name "/web" is already in use by container "9c1f3a7b...". docker ps lists nothing. docker ps -a --filter name=web lists one row, ID 9c1f3a7b2e64, status Exited (0) 14 hours ago, name web. docker inspect shows the image app:1.4 created yesterday. The script never used --rm. The administrator renames the container to web-old-2026-12-02 by its ID, runs the script again, and removes the old one after a week.

Confirm the fix

  1. docker ps -a --filter name=web lists the new container with status Up and, if you renamed, the old one under its new name.
  2. The script or docker compose up ends without the conflict message.
  3. If you used --rm going forward, an exited container no longer remains listed.

What to watch afterwards

  • Add --rm to short runs, or remove named containers in the script before starting them again, only where the container holds no state you need; Docker's page gives no way to undo a removal (see "Remove the holder").
  • Docker's docker container prune command removes all stopped containers, and Docker's page gives no way to undo it.
  • A manually stopped container under a restart policy can return when the daemon restarts, per Docker's restart page. Rename it if the name must stay free.
  • Do not give two Compose projects the same container_name.

Risks and limits

  • These commands have not been run or lab-tested.
  • Removing a container deletes its writable layer, and Docker's page gives no way to get it back; named volumes are not removed by docker rm, per Docker's page, and anonymous ones are removed only with -v.
  • The message text is a reading of moby v27.3.1; newer releases may word it differently.
  • The name filter matches parts of names. Always confirm the ID before renaming or removing.

Sources