我在Windows10上运行Docker。
在docker容器运行命令中添加--rm应在退出时移除我的容器,但从一段时间以来,如果我键入
docker container run -p 80:80 --rm nginx
我得到了
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
并且nginx在我的停靠机IP地址上运行良好,但是如果我键入
ctrl+C
我用docker container ls
检查我的容器,我发现容器仍然在运行:
$ docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
012963897aa4 nginx "/docker-entrypoint.…" 2 minutes ago Up 2 minutes 0.0.0.0:80->80/tcp affectionate_dhawan
为什么?
发布于 2021-05-03 23:19:13
将
--rm
添加到停靠容器运行命令中,应该在退出容器时删除它,。
这是一种误解。--rm
标志告诉Docker在容器停止时删除它。
我看到您没有向您的docker container run
命令传递额外的标志,所以我假设您在启动容器后附加到容器上。从容器中分离的不会自动停止,除非容器是用-i
标志启动的,该标志应该使用该运行命令将stdin/stdout自动附加到容器上。
要删除使用--rm
标志启动的容器,只需设置docker stop
,它就会消失。
https://stackoverflow.com/questions/67376888
复制相似问题