docker停止并删除容器

这是一个非常基本的问题。 可以停止并移除像这样的docker集装箱。

docker stop <container_id> docker rm <container_id> 

这是一样的吗?

 docker rm -f <container_id> 

如果他们不一样,使用后者有什么负面影响?

我已经看到单一的命令停止和删除docker集装箱 。 但是这并不能回答我的问题。

他们是类似的,你可以检查手册页:

 Usage: docker rm [OPTIONS] CONTAINER [CONTAINER...] Remove one or more containers -f, --force Force the removal of a running container (uses SIGKILL) 

 Usage: docker stop [OPTIONS] CONTAINER [CONTAINER...] Stop a running container. Sending SIGTERM and then SIGKILL after a grace period --help Print usage -t, --time=10 Seconds to wait for stop before killing it 

我会说

 docker stop <container_id> docker rm <container_id> 

会更加“优雅”,因为它在SIGKILL之前首先发送一个SIGTERM ,这将给Docker一个清理的机会。