docker run->'名称已被容器使用'

'name is already in use by container'

Running the docker registry with below command always throws an error: 使用以下命令运行docker注册表始终会引发错误:

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 ? 如何防止此错误?


#1楼

参考:https://stackoom.com/question/2903I/docker-run-gt-名称已被容器使用


#2楼

That means you have already started a container in the past with the parameter docker run --name registry-v1 ... . 这意味着您过去已经使用参数docker run --name registry-v1 ...启动了一个容器。

You need to delete that first before you can re-create a container with the same name with docker rm registry-v1 . 您需要先删除该容器,然后才能使用docker rm registry-v1重新创建具有相同名称的容器。 When that container is sill running you need to stop it first before you can delete it with docker stop registry-v1 . 当该容器仍处于运行状态时,您需要先将其停止,然后才能使用docker stop registry-v1将其删除。 Or simply choose a different name for the new container. 或者只是为新容器选择其他名称。

To get a list of existing containers and their names simply invoke docker ps -a . 要获取现有容器及其名称的列表,只需调用docker ps -a


#3楼

I got confused by this also. 我也为此感到困惑。 There are two commands relevant here: 这里有两个相关命令:

docker run Run a command in a new container docker run容器中运行命令

docker start Start one or more stopped containers docker start启动一个或多个已停止的容器


#4楼

You have 2 options to fix this... 您有2个解决此问题的方法...

  1. Remove previous container using that name, with the command docker rm $(docker ps -aq --filter name=myContainerName) 使用命令docker rm $(docker ps -aq --filter name=myContainerName)使用该名称删除以前的容器

    OR 要么

  2. Rename current container to a different name ie change this portion --name registry-v1 to something like --name myAnotherContainerName 将当前容器重命名为其他名称,即,将--name registry-v1这一部分更改为--name myAnotherContainerName

You are getting this error because that container name ( ie registry-v1 ) was used by another container in the past...even though that container may have exited ie (currently not in use). 之所以出现此错误,是因为该容器名称(即registry-v1 )过去曾被另一个容器使用过...即使该容器可能已经退出(即(当前未使用))。


#5楼

You can remove it with command sudo docker rm YOUR_CONTAINER_ID , then run a new container with sudo docker run ... ; 您可以使用sudo docker rm YOUR_CONTAINER_ID命令将其删除,然后使用sudo docker run ... sudo docker rm YOUR_CONTAINER_ID sudo docker run ...运行一个新容器。 or restart an existing container with sudo docker start YOUR_CONTAINER_ID 或使用sudo docker start YOUR_CONTAINER_ID重新启动现有容器, sudo docker start YOUR_CONTAINER_ID


#6楼

I'm just learning docker and this got me as well. 我只是在学习docker,这也让我受益。 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. 当我运行docker ps -a时,我看到了我在玩耍时创建的所有虚拟测试容器。

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. 没问题,因为我不再想要那些了,所以我只做了docker rm containername ,这时我的新容器可以用旧名称运行。

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 嗯,现在我完成了这个答案的编写,我看到了Slawosz对Walt Howard的答案的评论,上面建议使用docker docker ps -a

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值