问题描述
我首先得到了我的nginx码头图像:docker pull nginx
/ pre>
然后我开始了:
docker run -d -p 80:80 --name webserver nginx
然后我停止了:
docker stop webserver
然后我尝试重新启动它:
$ docker run -d -p 80:80 --name webserver nginx
docker:来自守护程序的响应错误:冲突。容器名称/ webserver已经被容器036a0bcd196c5b23431dcd9876cac62082063bf62a492145dd8a55141f4dfd74使用。您必须删除(或重命名)该容器才能重用该名称。
请参阅'docker run --help'。
那是一个错误。但事实上,现在容器列表中没有任何内容:
docker容器列表
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
为什么我重新启动nginx图像失败?如何解决?
解决方案这是因为
- 您已经使用
- 名称
开关。 - 容器已停止,未删除
您发现它已停止
docker ps -a
您可以使用以下命令启动它:
docker start webserver
编辑:替代方案
如果要每次启动带有以下命令的容器,
docker run -d -p 80:80 --name webserver nginx
然后使用以下之一:
方法1:使用 -rm
switch ie,一旦停止,容器会自动破坏
码头服务器运行-d -p 80:80 --rm --name webserver nginx
方法2:在启动您当前正在使用的命令之前,请先停止容器,然后将其清除。
docker stop< container name> ;
docker rm< container name>
I first got my nginx docker image:
docker pull nginx
Then I started it:
docker run -d -p 80:80 --name webserver nginx
Then I stopped it:
docker stop webserver
Then I tried to restart it:
$docker run -d -p 80:80 --name webserver nginx
docker: Error response from daemon: Conflict. The container name "/webserver" is already in use by container 036a0bcd196c5b23431dcd9876cac62082063bf62a492145dd8a55141f4dfd74. You have to remove (or rename) that container to be able to reuse that name..
See 'docker run --help'.
Well, it's an error. But in fact there's nothing in container list now:
docker container list
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
Why I restart nginx image failed? How to fix it?
It is because
- you have used
--name
switch. - container is stopped and not removed
You find it stopped
docker ps -a
You can simply start it using below command:
docker start webserver
EDIT: AlternativesIf you want to start the container with below command each time,
docker run -d -p 80:80 --name webserver nginx
then use one of the following:
method 1: use --rm
switch i.e., container gets destroyed automatically as soon as it is stopped
docker run -d -p 80:80 --rm --name webserver nginx
method 2: remove it explicitly after stopping the container before starting the command that you are currently using.
docker stop <container name>
docker rm <container name>
这篇关于docker重新启动容器失败:“已经在使用”,但是没有更多的docker图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!