How to fix Error response from daemon: Conflict. The container name '/mycontainer' is already in use by container in Docker
This error occurs when you try to create or start a Docker container with a name that's already taken by an existing container. Even stopped containers keep their names until removed.
Quick fix
Fixes Error response from daemon: Conflict. The container name '/mycontainer' is already in use by container
docker ps -a- List all containers to identify the conflict
- Remove the existing container
- Alternative: Start the existing container instead
- Alternative: Use a different name or let Docker auto-name
docker ps -aError response from daemon: Conflict. The container name '/mycontainer' is already in use by container
What this error means
This error message indicates that Docker cannot create or start a new container because another container with the same name already exists on your system. Docker requires each container to have a unique name, even if the container is currently stopped. When you use the `--name` flag with `docker run`, Docker assigns that specific name to the container. If a container with that name already exists (whether running or stopped), Docker will refuse to create a new container with the same name to avoid conflicts. This is a protective measure - stopped containers aren't automatically deleted because they can be restarted and retain all their configuration, volumes, and state. Docker treats container names as unique identifiers across all containers on the host.
Typical symptoms
- Docker run command fails with 'Conflict' error message
- Error mentions specific container name is 'already in use'
- Cannot start a new container despite no visible running containers
- Docker Compose fails to create services with pre-existing container names
- CI/CD pipelines fail when trying to recreate containers with fixed names
Common causes
- A stopped container exists with the same name you're trying to use
- Previous container run failed or exited but wasn't removed
- Docker Compose containers from previous runs weren't cleaned up
- You're running the same docker run command repeatedly without --rm flag
- Container crashed or was killed but still exists in stopped state
- Multiple developers or scripts using the same hardcoded container names
How to fix "Error response from daemon: Conflict. The container name '/mycontainer' is already in use by container"
First, check which containers exist on your system, including stopped ones:
docker ps -aThis shows all containers with their names, IDs, and current status. Look for the container name mentioned in your error message.
Example output:
CONTAINER ID IMAGE COMMAND CREATED STATUS NAMES
abc123def456 nginx ... 2 hours ago Exited (0) 2 hours ago mycontainerOnce you've identified the conflicting container, remove it by name or ID:
docker rm mycontainerOr using the container ID:
docker rm abc123def456If the container is still running, you need to stop it first:
docker stop mycontainer
docker rm mycontainerOr force remove it in one command (stops and removes):
docker rm -f mycontainerAfter removal, you can create a new container with that name.
If you want to reuse the existing container rather than create a new one:
docker start mycontainerThis is useful when:
- The container has the configuration you need
- You want to preserve volumes and state
- You're just restarting after a system reboot
To check if the container started successfully:
docker psYou can avoid the conflict by choosing a different name:
docker run --name mycontainer-2 nginxOr omit the --name flag entirely - Docker will assign a random name:
docker run nginxDocker generates names like "quirky_einstein" or "elegant_turing" automatically.
If you're running temporary or one-off containers, use the --rm flag to automatically remove the container when it stops:
docker run --rm --name mycontainer nginxThis prevents name conflicts on subsequent runs and keeps your system clean. Perfect for:
- Test runs
- One-time scripts
- Development containers that don't need persistence
Advanced notes
Cleaning up multiple stopped containers:
To remove all stopped containers at once:
docker container pruneDocker will prompt for confirmation. Use -f to skip the prompt:
docker container prune -fYou can also filter by age:
docker container prune --filter "until=24h"Docker Compose considerations:
When using Docker Compose, container names are auto-generated from project, service, and replica number. If you've specified custom container names in your docker-compose.yml:
services:
web:
container_name: mycontainerYou'll encounter this error if the container exists. Use:
docker-compose downThis stops and removes containers defined in the compose file.
Race conditions in CI/CD:
In automated environments, use idempotent patterns:
docker stop mycontainer 2>/dev/null || true
docker rm mycontainer 2>/dev/null || true
docker run --name mycontainer nginxOr combine start/run logic:
docker start mycontainer || docker run --name mycontainer nginxContainer name format:
Valid container names must match the pattern [a-zA-Z0-9][a-zA-Z0-9_.-]*. Names are case-sensitive and cannot contain special characters except underscore, period, and hyphen.
Frequently asked questions
- What does "Error response from daemon: Conflict. The container name '/mycontainer" mean?
- This error message indicates that Docker cannot create or start a new container because another container with the same name already exists on your system. Docker requires each container to have a unique name, even if the container is currently stopped. When you use the --name flag with docker run, Docker assigns that specific name to the container.
- How do I fix "Error response from daemon: Conflict. The container name '/mycontainer"?
- This error occurs when you try to create or start a Docker container with a name that's already taken by an existing container. Even stopped containers keep their names until removed.
- What causes "Error response from daemon: Conflict. The container name '/mycontainer"?
- A stopped container exists with the same name you're trying to use Previous container run failed or exited but wasn't removed Docker Compose containers from previous runs weren't cleaned up
- Is the "Error response from daemon: Conflict. The container name '/mycontainer" error serious?
- It is a low-severity error โ more of a blocker than a risk. The steps above resolve it.
Official resources & further reading
- ๐Docker Official Documentation
- ๐Source(GitHub)