docker run -> name is already in use by container

2019-01-29 19:46发布

Running the docker registry with below command always throws an error:

dev:tmp me$ docker run \
     -d --name registry-v1 \
     -e SETTINGS_FLAVOR=local \
     -e STORAGE_PATH=/registry \
     -e SEARCH_BACKEND=sqlalchemy \
     -e LOGLEVEL=DEBUG \
     -p 5000:5000 \
     registry:0.9.1
Error response from daemon: Conflict. The name "registry-v1" is already in use by container f9e5798a82e0. You have to delete (or rename) that container to be able to reuse that name.

How to prevent this error ?

标签: docker
9条回答
We Are One
2楼-- · 2019-01-29 20:24

I got confused by this also. There are two commands relevant here:

docker run Run a command in a new container

docker start Start one or more stopped containers

查看更多
姐就是有狂的资本
3楼-- · 2019-01-29 20:25

I'm just learning docker and this got me as well. I stopped the container with that name already and therefore I thought I could run a new container with that name.

Not the case. Just because the container is stopped, doesn't mean it can't be started again, and it keeps all the same parameters that it was created with (including the name).

when I ran docker ps -a that's when I saw all the dummy test containers I created while I was playing around.

No problem, since I don't want those any more I just did docker rm containername at which point my new container was allowed to run with the old name.

Ah, and now that I finish writing this answer, I see Slawosz's comment on Walt Howard's answer above suggesting the use of docker ps -a

查看更多
家丑人穷心不美
4楼-- · 2019-01-29 20:27

Just to explain what others are saying (it took me some time to understand): simply put when you see this error, it means you already have a container and what you have to do is run it. While intuitively docker run is supposed to run, it doesn't. The command docker run is used to only START a container for the very first time. To run an existing container what you need is docker start $container-name. So much for asking developers to create meaningful/intuitive commands.

查看更多
登录 后发表回答