Docker "Conflict. The container name is already in use" in CI
By Daniel Zoghalchali·Latchkey
You started a container with a fixed --name, but a container with that name already exists. Docker names must be unique, so the daemon refuses to create a second one.
What this error means
A docker run --name <x> fails with Conflict. The container name "/<x>" is already in use by container .... It often appears on a re-run, or on a long-lived runner where a previous job left the container behind.
docker run output
docker: Error response from daemon: Conflict. The container name "/postgres-test"
is already in use by container "a1b2c3...". You have to remove (or rename)
that container to be able to reuse that name.
Diagnose it: read the container, not the compose file
A container that exits immediately in CI has almost always logged the reason and then been cleaned up. Capture the logs and the exit code before changing configuration.
Terminal
# why did it stop?
docker ps -a --format '{{.Names}}\t{{.Status}}\t{{.Image}}'
docker logs <container> 2>&1 | tail -50
docker inspect <container> --format '{{.State.ExitCode}} {{.State.OOMKilled}} {{.State.Error}}'
Common causes
A previous run left the container behind
A container started with the same --name was not removed (the job failed before cleanup, or --rm was not used), so the name is still taken on a reused runner.
Two steps use the same fixed name
Parallel or repeated steps that all hardcode the same --name collide, because only one container can hold that name at a time.
How to fix it
Remove the existing container first, or use --rm
Clean up before starting, and auto-remove on exit so the name frees up.
Drop --name and let Docker generate a unique name, referencing the container by its ID.
Or suffix the name with a unique value (run id, timestamp).
Add a cleanup step that removes the container even when the job fails.
How to prevent it
Use --rm for ephemeral CI containers so they self-clean.
Avoid hardcoded --name values that can collide across runs/steps.
Add an always-run cleanup step on long-lived runners.
Frequently asked questions
What causes Docker "Conflict. the container name is already in use" in CI?
There are 2 common causes: a previous run left the container behind and two steps use the same fixed name. A container started with the same --name was not removed (the job failed before cleanup, or --rm was not used), so the name is still taken on a reused runner.
How do I fix Docker "Conflict. the container name is already in use" in CI?
There are 2 fixes depending on which cause you have: remove the existing container first, or use --rm and use unique names or let docker assign one. Work through them in order, since the first is the most common.
What does Docker "Conflict. the container name is already in use" in CI actually mean?
A docker run --name <x> fails with Conflict.
How do I stop Docker "Conflict. the container name is already in use" in CI happening again?
Use --rm for ephemeral CI containers so they self-clean. The prevention section lists 3 changes that keep it from recurring.