← Back to Error Lab

Docker: error response from daemon: Conflict. The container name is already in use

Published 2026-04-16

Educational use only. Content explains errors and defensive fixes for systems you own or are authorised to test. Do not use any technique here to access data, accounts, or networks without permission.

Root Cause

Docker requires every container to have a unique name. This error occurs when you attempt to start or run a new container using a name (via the `--name` flag) that is already assigned to an existing container, even if that existing container is currently stopped or exited. Docker preserves stopped containers so you can inspect their logs or restart them. Until the old container is explicitly removed, its name remains reserved.

Fix / Solution

You have two choices: either assign a different, unique name to the new container, or remove the existing container to free up the name. You can find the conflicting container using `docker ps -a`. To remove it, use `docker rm <container_name>`. If you want Docker to automatically clean up containers when they exit, use the `--rm` flag when running them.

Code Snippet

# ❌ Fails if 'my-db' already exists (even if stopped)
docker run --name my-db -d postgres

# ✅ Option 1: Remove the old container first
docker rm -f my-db
docker run --name my-db -d postgres

# ✅ Option 2: Use an ephemeral container
docker run --rm --name my-db-temp -d postgres