简体   繁体   中英

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

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

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

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.

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

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'(ie 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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM