docker image重启,docker重新启动容器失败:“已经在使用”,但是没有更多的docker图像...

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

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

docker rm

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值