Skip to content

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.

The image builds successfully, then container creation fails with a message like:

Terminal window
Error response from daemon: Conflict. The container name "/my_project" is already in use ...

Show all containers on the system, including stopped ones.

Terminal window
docker ps -a

Filter to the names likely in conflict if needed. Adjust the pattern to match your service and project names.

Terminal window
docker ps -a | grep -E 'frontend|backend|redis|mysql'

Force remove the containers holding the names. This frees the fixed names so new ones can be created.

Terminal window
docker rm -f my_project 2>/dev/null

With the old names freed, recreate the stack. The –build flag is only needed if code, Dockerfile, or compose config changed.

Terminal window
docker compose up --build