简体   繁体   English

无法自动停止运行jupyter笔记本的容器

[英]unable to automatically stop container running jupyter notebook

If I start a container with --rm like so: 如果我像这样用--rm启动一个容器:

docker run --rm -it image-name /bin/bash

Then from the repl I can close it exit and it automatically removes the container, so I don't have to. 然后,我可以从repl关闭exit ,它会自动删除容器,因此我不必这样做。

It's very nice. 这是很不错的。

But now I'm starting a container and telling it to automatically run jupyter notebook like so: 但是现在我要启动一个容器,并告诉它像这样自动运行jupyter notebook:

docker run --rm -it image-name /bin/bash -c "jupyter notebook ..."

In this case, when I press control+c I exit the container, but it doesn't shut down the container, because jupyter notebook is still running. 在这种情况下,当我按control+c我退出了容器,但是它没有关闭容器,因为jupyter notebook仍在运行。 Then I have to go in and docker stop container-id and then docker rm container-id which is annoying. 然后我必须进去, docker stop container-id ,然后是docker rm container-id ,这很烦人。

Is there any way to tell the container to automatically close when I exit it? 有什么方法可以让容器在退出时自动关闭?

So the reason the container removes itself in the first scenario is because the "bash" script is what your execution was tied to. 因此,在第一种情况下容器将自身删除的原因是“ bash”脚本是您执行的对象。 When you exit, BASH exits, so the container is removed. 退出时,BASH退出,因此将容器移除。

In the second scenario, you're not actually doing that. 在第二种情况下,您实际上并没有这样做。 You're executing a command interactively via bash's command function, and you exiting the terminal isn't tied to the termination of that command. 您正在通过bash的命令功能以交互方式执行命令,而退出终端与该命令的终止无关。

The way the Docker --rm flag works is that, once the command requested by the execution statement ends, remove the container". If you execute bash to get an interactive shell, and then run the command, you'll get a different experience. Docker --rm标志的工作方式是,一旦执行语句请求的命令结束,则删除容器。”如果执行bash以获取交互式shell,然后运行该命令,您将获得不同的体验。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM