Docker "Conflict. The container name is already in use" in CI
A docker run --name <name> collided with an existing container. Conflict. The container name "/<name>" is already in use means a prior container with that name still exists (running or stopped) and was not removed.
What this error means
A docker run --name api ... fails with Error response from daemon: Conflict. The container name "/api" is already in use by container "<id>". You have to remove (or rename) that container to be able to reuse that name.
docker: Error response from daemon: Conflict. The container name "/api" is already
in use by container "9f3c...". You have to remove (or rename) that container to reuse that name.Common causes
A previous container with the same name was not removed
A fixed --name reused across jobs (or a re-run) collides with the leftover container from the prior run on a persistent runner.
A stopped container still holds the name
Container names are reserved even when stopped; a stopped container with that name blocks reuse until removed.
How to fix it
Remove the existing container or use --rm
Remove the old container first, or run with --rm / a unique name.
docker rm -f api 2>/dev/null || true
docker run --name api --rm myorg/api:1.4.2
# or avoid fixed names:
docker run myorg/api:1.4.2 # daemon assigns a unique nameUse unique per-run names
Suffix the name with a run identifier so collisions cannot happen.
docker run --name "api-${{ github.run_id }}" --rm myorg/api:1.4.2How to prevent it
- Use
--rmor unique per-run container names in CI. - Remove fixed-name containers before re-running on persistent runners.
- Avoid hard-coded
--namevalues shared across jobs.