Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trouble creating a new container in Docker. Error response from daemon: Conflict. The container name is already in use by container

Tags:

docker

macos

I'm running the intro tutorial for Docker on Mac and am getting an error as follows:

docker run -d -p 80:80 --name docker-tutorial docker101tutorial

docker: Error response from daemon: Conflict. The container name "/docker-tutorial" is already in use by container "c5a91ef51a529a00dcbef180560dc2b392f3d9ab05b8c29fa1bf640d64271de7". You have to remove (or rename) that container to be able to reuse that name. See 'docker run --help'.

Can you advise on this error — it seems that I would need to delete a prior container? But I don't believe I created one.

Can anyone please advise as to how to troubleshoot this issue as I am not very proficient in terminal and am new to Docker.

When I type docker ps -a, I get:

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                        PORTS               NAMES
f5ed32612a0a        ubuntu              "bash"                   27 minutes ago      Exited (129) 22 minutes ago                       happy_tesla
b179c651b8d7        hello-world         "/hello"                 40 minutes ago      Exited (0) 40 minutes ago                         mystifying_rubin
c5a91ef51a52        docker101tutorial   "/docker-entrypoint.…"   42 minutes ago      Created                                           docker-tutorial
916e57976203        hello-world         "/hello"                 48 minutes ago      Exited (0) 48 minutes ago                         exciting_dewdney
like image 539
don Avatar asked Jun 03 '20 09:06

don


People also ask

Can docker container have same name?

You have to remove (or rename) that container to be able to reuse that name. See 'docker run --help'.

How do I restart docker daemon?

Restart the Docker daemon. On Linux, you can avoid a restart (and avoid any downtime for your containers) by reloading the Docker daemon. If you use systemd , then use the command systemctl reload docker . Otherwise, send a SIGHUP signal to the dockerd process.


4 Answers

To make it short, the reason why this is happening to you is because, when you name containers (with the flag --name foo), then you have to make sure this name is unique among all the containers you have on your host.

Then regarding your statement:

Can you advise on this error - it seems that I would need to delete a prior container? But I don't believe I created one

If I read your docker ps -a output, this is untrue, you created one 42 minutes ago, see the really last bit of the below line? This is the name of an existing container, docker-tutorial:

c5a91ef51a52        docker101tutorial   "/docker-entrypoint.…"   42 minutes ago      Created                                           docker-tutorial

Just run:

docker rm docker-tutorial

Then you should be able to go back your tutorial.


For the sake of completeness, since it can be unexpected at first usage, the command docker rm will output back the name of the container that it just deleted:

$ docker rm I-do-exist                  
I-do-exist

And if you do not have such a named container, then it will output a clear error:

$ docker rm I-do-not-exist
Error: No such container: I-do-not-exist
like image 143
β.εηοιτ.βε Avatar answered Nov 15 '22 05:11

β.εηοιτ.βε


The command being docker run and not run, I suspect there might be some typo, maybe a non-printable character.

Try to type the complete command from a fresh prompt.

like image 22
Olivier Lépine Avatar answered Nov 15 '22 05:11

Olivier Lépine


Please post the command you are running again removing the backslash

Please post output docker ps -a it will show you what containers are there running/stopped

like image 29
HumayunM Avatar answered Nov 15 '22 04:11

HumayunM


You can solve your problem with just two commands

In your terminal type:

  1. docker ps -qa

to find the name that you called your docker container and check the its status says 'exited'(i.e. Container called 'Zen-wu')

  1. Select your docker container number and remove it like the example below

docker rm 828a52b426f2

optional

If you want to remove All the exited docker containers do the following command

docker rm $(docker ps -qa)

like image 22
fypnlp Avatar answered Nov 15 '22 03:11

fypnlp