Skip to content
The container name "/..." is already in use

The container name "/..." is already in use

DodaTech 2 min read

The “container name is already in use” error occurs when you try to create a container with a name that is already assigned to an existing container. Every container name must be unique on a single Docker host.

What It Means

Docker requires unique container names within the same Docker host. When you run docker run --name my-app ... and my-app already exists (running or stopped), Docker refuses to create the new container.

Why It Happens

  • You ran the same docker run command twice without removing the first container.
  • A previous container with that name exists in the “exited” state.
  • You are re-creating a container during development without cleaning up old ones.
  • A CI/CD pipeline or script does not remove containers between runs.

How to Fix It

1. Remove the existing container

docker rm <container-name>

Force removal if the container is still running:

docker rm -f <container-name>

2. Verify the container is gone

docker ps -a | grep <container-name>

No output means the container was successfully removed.

3. Re-run with the container name

docker run --name my-container -d nginx

4. Use a different name

docker run --name my-container-v2 -d nginx

5. Use the --rm flag for ephemeral containers

The --rm flag automatically removes the container when it stops, preventing stale name conflicts:

docker run --rm --name my-container nginx

6. List all existing container names to check

docker ps -a --format "table {{.Names}}\t{{.Status}}"

FAQs

Is there a 'docker rename' command?
Yes. You can rename a container without recreating it: docker rename <old-name> <new-name>. This is useful when you want to free up a name without destroying the existing container.
Can I run containers without specifying a name?
Yes. If you omit --name, Docker assigns a random name like angry_swanson. The only requirement is that whatever name is used must be unique.
Does Docker Compose have the same naming limitation?
Yes. Docker Compose derives container names from the service name and project name (e.g., project_web_1). If you down and up the stack, old containers are removed automatically. Use docker compose down before up to avoid conflicts.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro