container name is already in use
DockerERRORStartupHIGH confidence

A container with the specified name already exists

What this means

This error occurs when you attempt to create and name a new container with '--name', but a container (either running or stopped) with that exact name already exists. Container names must be unique within a Docker host.

Why it happens
  1. 1A script or command is trying to create a container that was already created in a previous run.
  2. 2You are trying to run a new version of a container without first removing the old one.
  3. 3A stopped container with that name still exists and has not been removed.
  4. 4Two different processes or users are trying to create a container with the same name at the same time.
How to reproduce

You run a 'docker run' command with a specific name, and then run the exact same command a second time.

trigger — this will error
trigger — this will error
# The first command succeeds
docker run -d --name my-webserver nginx
# The second command fails
docker run -d --name my-webserver nginx

expected output

docker: Error response from daemon: Conflict. The container name "/my-webserver" is already in use by container "...". You have to remove (or rename) that container to be able to reuse that name.

Fix 1

Remove the Existing Container

WHEN The existing container is old or disposable and can be safely deleted.

Remove the Existing Container
# The 'docker rm -f' command forcefully removes the container
docker rm -f my-webserver

Why this works

This deletes the conflicting container, freeing up the name for a new container to use.

Fix 2

Use the '--rm' Flag

WHEN Running temporary containers that should be cleaned up automatically on exit.

Use the '--rm' Flag
docker run --rm -it --name my-temp-task ubuntu bash

Why this works

This flag tells Docker to automatically remove the container when it exits, preventing name conflicts on subsequent runs of the same command.

Fix 3

Do Not Specify a Name

WHEN You don't need a predictable name and just want a container to run.

Do Not Specify a Name
docker run -d nginx

Why this works

If you omit the '--name' flag, Docker will automatically assign a unique, randomly generated name (e.g., 'jolly_wozniak'), avoiding conflicts entirely.

What not to do

Create complex scripts to generate unique names.

This is over-engineering. It's much simpler and more idiomatic to either remove the old container before creating a new one, or let Docker assign a random name.

Sources
Official documentation ↗

Docker run reference (--name)

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All Docker errors