Docker重启容器失败:"已经在使用中“,但没有更多的码头图像 [英] docker restart container failed: "already in use", but there's no more docker image

查看:18
本文介绍了Docker重启容器失败:"已经在使用中“,但没有更多的码头图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我首先得到了我的 nginx docker 镜像:

I first got my nginx docker image:

docker pull nginx

然后我开始它:

docker run -d -p 80:80 --name webserver nginx

然后我停止了:

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

为什么我重启 nginx 镜像失败了?如何解决?

Why I restart nginx image failed? How to fix it?

推荐答案

是因为

  • 您已使用 - name switch.
  • 容器停止而未删除

你发现它停止了

docker ps -a

您可以简单地使用以下命令启动它:

You can simply start it using below command:

docker start webserver

替代方案如果要每次使用以下命令启动容器,

Alternatives If 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:

方法1:使用 - rm switch i.e,一旦停止,容器会自动销毁

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

方法2:在启动您当前使用的命令之前停止容器后明确地删除它.

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重启容器失败:&QUOT;已经在使用中“,但没有更多的码头图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆