MrMino / dockernel

Dockerized Jupyter kernels
MIT License
56 stars 15 forks source link

Stop docker container after closing kernel #10

Closed vmenger closed 3 years ago

vmenger commented 3 years ago

Currently, docker containers keep running when a kernel/notebook is closed. This can start eating up a lot of resources over time.

To investigate:

gogasca commented 3 years ago

I have the same issue. When a kernel stopped, I would be interested in capturing that signal and call the docker stop command. I would assume we would need to collect the docker image id to be able to call correctly docker stop. I'm not a iPython kernel expert but seems to be this needs to be handled directly by a Kernel Manager such as here: https://github.com/jupyter/notebook/blob/master/notebook/services/kernels/kernelmanager.py

This is my kernel.json file.

{
 "argv": [
  "/usr/bin/docker",
  "run",
  "--network=host",
  "-v",
  "{connection_file}:/connection-spec",
  "gcr.io/deeplearning-platform-release/tf2-cpu.2-4:latest",
  "python",
  "-m",
  "ipykernel_launcher",
  "-f",
  "/connection-spec"
 ],
 "display_name": "tensorflow",
 "language": "python"
}

Update: Not able to reproduce it anymore. Will investigate further

vmenger commented 3 years ago

The normal behaviour for a container when running in the background is to stop whenver the CMD/ENTRYPOINT command stops. In this case the ipykernel receives the shutdown command, after which it terminates and the docker should automatically terminate.

For this project it works correctly most of the time, but in some cases the docker keeps running. I have yet to find a complete reproducible case, but will update if I find one.

MrMino commented 3 years ago

@vmenger @gogasca IIRC, back at the time I was developing the first release I had the same problem. Changing the default interrupt mode fixed the issue. I don't think this change was released, but it's merged to master (5ca4d069d11b25b5e58573fbceb6cc510eace165).

BTW. I've just realized that the release I've put out on PyPI either disappeared or was never deployed properly in the first place. Fixing this as we speak. 1.0.1 with the change mentioned above is coming too.

MrMino commented 3 years ago

There you go. dockernel==1.0.1 should fix this issue.

I have no idea why I left all of this without releasing it properly, sorry for that.

MrMino commented 3 years ago

Closing this one. If anyone has this same problem again - please make sure it's dockernel==1.0.2 and if so, create a new issue. Thanks!