docker container name already in use — how to fix
Quick Answer
# Remove the existing container
docker rm my-container
# Or stop it first, then remove
docker stop my-container && docker rm my-container
# Auto-remove when the container exits (for one-off runs)
docker run --rm --name my-container my-image
When this happens
docker: Error response from daemon: Conflict. The container name "/my-container"
is already in use by container "abc123". You have to remove (or rename) that
container to be able to reuse that name.
A stopped (but not removed) container is holding the name. Stopped containers persist until explicitly removed.
Other causes & fixes
List all containers including stopped ones
docker ps -a
# CONTAINER ID IMAGE STATUS NAMES
# abc123 my-image Exited my-container ← this one
Rename instead of remove
docker rename my-container my-container-old
docker run --name my-container my-image
Remove all stopped containers
docker container prune
Related