How to fix Error response from daemon: Conflict. The container name '/mycontainer' is already in use by container in Docker

DockerBEGINNERLOWUpdated Dec 6, 2025ยท 297 views

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
  1. List all containers to identify the conflict
  2. Remove the existing container
  3. Alternative: Start the existing container instead
  4. Alternative: Use a different name or let Docker auto-name
docker โ€” error
docker ps -a
Error 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

  1. A stopped container exists with the same name you're trying to use
  2. Previous container run failed or exited but wasn't removed
  3. Docker Compose containers from previous runs weren't cleaned up
  4. You're running the same docker run command repeatedly without --rm flag
  5. Container crashed or was killed but still exists in stopped state
  6. 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"

1List all containers to identify the conflict

First, check which containers exist on your system, including stopped ones:

bash
docker ps -a

This shows all containers with their names, IDs, and current status. Look for the container name mentioned in your error message.

Example output:

bash
CONTAINER ID   IMAGE     COMMAND   CREATED        STATUS                    NAMES
abc123def456   nginx     ...       2 hours ago    Exited (0) 2 hours ago    mycontainer
2Remove the existing container

Once you've identified the conflicting container, remove it by name or ID:

bash
docker rm mycontainer

Or using the container ID:

bash
docker rm abc123def456

If the container is still running, you need to stop it first:

bash
docker stop mycontainer
docker rm mycontainer

Or force remove it in one command (stops and removes):

bash
docker rm -f mycontainer

After removal, you can create a new container with that name.

3Alternative: Start the existing container instead

If you want to reuse the existing container rather than create a new one:

bash
docker start mycontainer

This 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:

bash
docker ps
4Alternative: Use a different name or let Docker auto-name

You can avoid the conflict by choosing a different name:

bash
docker run --name mycontainer-2 nginx

Or omit the --name flag entirely - Docker will assign a random name:

bash
docker run nginx

Docker generates names like "quirky_einstein" or "elegant_turing" automatically.

5For temporary containers: Use the --rm flag

If you're running temporary or one-off containers, use the --rm flag to automatically remove the container when it stops:

bash
docker run --rm --name mycontainer nginx

This 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:

bash
docker container prune

Docker will prompt for confirmation. Use -f to skip the prompt:

bash
docker container prune -f

You can also filter by age:

bash
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:

yaml
services:
  web:
    container_name: mycontainer

You'll encounter this error if the container exists. Use:

bash
docker-compose down

This stops and removes containers defined in the compose file.

Race conditions in CI/CD:

In automated environments, use idempotent patterns:

bash
docker stop mycontainer 2>/dev/null || true
docker rm mycontainer 2>/dev/null || true
docker run --name mycontainer nginx

Or combine start/run logic:

bash
docker start mycontainer || docker run --name mycontainer nginx

Container 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