Conflict. The container name "/fix4-web" is already in use by container "..."
— a container with that name already exists, running or stopped, and Docker names must be
unique. Either start the existing container with docker start, or remove it with
docker rm -f and run your command again.
Which one you want depends on the data inside. docker start keeps everything
the old container wrote; docker rm -f throws the container away (named volumes
survive) and lets docker run create a fresh one with your new options.
The error
docker run -d --name fix4-web -p 15450:5432 -e POSTGRES_PASSWORD=fix4test postgres:18
docker: Error response from daemon: Conflict. The container name "/fix4-web" is already in use by container "f11399fd277bbbc91898e90a2ef50c3288a173bc6c67b23d8bfa9617d0843437". You have to remove (or rename) that container to be able to reuse that name.
Run 'docker run --help' for more information
fix4-web, the password and port 15450 are the test's own names; yours will
differ.
Why it happens
docker run is two steps in one: create a container, then start it. The create
step registers the name you passed with --name, and that name stays taken
until the container is removed, not merely until it stops. So the second run of the same
command, the morning after a reboot or in a script that runs twice, collides with the
container from the first run even when docker ps shows nothing; add
-a to see stopped containers too.
The leading slash in "/fix4-web" is how the engine stores container names
internally; it is not part of the name you type.
The fix
To keep the existing container and its data, start it:
docker start fix4-web
fix4-web
To replace it with a new container, remove the old one first:
docker rm -f fix4-web
fix4-web
docker run -d --name fix4-web -p 15450:5432 -e POSTGRES_PASSWORD=fix4test postgres:18
833c56d7b7425a0f470edbe50709c4982d5006feaa98257f65e09ac34fe5abc5
-f removes the container even while it is running. For throwaway containers,
add --rm to docker run so Docker removes the container (and its
name) as soon as it exits. In scripts, the remove-then-run pair is the usual pattern; for
anything with state you care about, use Docker Compose, which reuses or recreates the
container for you.
How it was reproduced
On Windows 11 with Docker Desktop 4.91 (client and engine 29.8.2) and the cached
postgres:18 image (PostgreSQL 18.4). The same docker run -d --name
fix4-web command was run twice from PowerShell 5.1; the second one failed with exit
code 125. docker start fix4-web brought the first container back, and
docker rm -f followed by the original command created a new container with a
new id. The test container was removed at the end.
Frequently asked
- How do I fix container name is already in use in Docker?
- Run docker start with the name to reuse the existing container, or docker rm -f with the name to remove it, then run your docker run command again.
- Why is the container name in use when docker ps shows nothing?
- docker ps lists only running containers. A stopped container still owns its name; docker ps -a lists it.
- Does docker rm -f delete my database data?
- It deletes the container and anything stored only inside it. Data in a named volume survives and is attached again when the new container mounts the same volume.
More decoded errors in the Fixes category. If the new container then fails on its port, see port is already allocated.