Docker Container Name Conflict
When docker-compose.yml uses fixed container_name values, those names must be unique across the entire Docker daemon. Old containers from a previous project state can block new ones from being created, even after a successful image build.
Typical error
Section titled “Typical error”The image builds successfully, then container creation fails with a message like:
Error response from daemon: Conflict. The container name "/my_project" is already in use ...List existing containers
Section titled “List existing containers”Show all containers on the system, including stopped ones.
docker ps -aFilter to the names likely in conflict if needed. Adjust the pattern to match your service and project names.
docker ps -a | grep -E 'frontend|backend|redis|mysql'Remove conflicting containers
Section titled “Remove conflicting containers”Force remove the containers holding the names. This frees the fixed names so new ones can be created.
docker rm -f my_project 2>/dev/nullRebuild and recreate
Section titled “Rebuild and recreate”With the old names freed, recreate the stack. The –build flag is only needed if code, Dockerfile, or compose config changed.
docker compose up --build