简体   繁体   中英

unable to automatically stop container running jupyter notebook

If I start a container with --rm like so:

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.

It's very nice.

But now I'm starting a container and telling it to automatically run jupyter notebook like so:

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. Then I have to go in and docker stop container-id and then docker rm container-id which is annoying.

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. When you exit, BASH exits, so the container is removed.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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