Ctrl K

Docker Container Name Conflict

Resolve 'container name already in use' errors caused by leftover containers when docker compose up fails to recreate services.

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

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

Show all containers on the system, including stopped ones.

docker ps -a

Filter 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

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/null

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