Docker "Conflict. The container name is already in use" in CI
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: 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.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.
docker rm -f postgres-test 2>/dev/null || true
docker run --rm --name postgres-test -d postgres:16Use unique names or let Docker assign one
- Drop
--nameand 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
--rmfor ephemeral CI containers so they self-clean. - Avoid hardcoded
--namevalues that can collide across runs/steps. - Add an always-run cleanup step on long-lived runners.