Search code examples
linuxcentosdockerjupyter-notebook

Docker not responding to CTRL+C in terminal


Having an issue with Docker at the moment; I'm using it to run an image that launches an ipython notebook on startup. I'm looking to make some edits to ipython notebook itself, so I need to close it after launch.

However, hitting CTRL+C in the terminal just inputs "^C" as a string. There seems to be no real way of using CTRL+C to actually close the ipython notebook instance.

Would anyone have any clues as to what can cause this, or know of any solutions for it?


Solution

  • This post proposes CTRL-Z as a workaround for sending the process to background and then killing the process by its process id: Cannot kill Python script with Ctrl-C

    Possible problems:

    • The program catches ctrl-c and does nothing, very unlikely.

    • There are background processes that are not managed correctly. Only the main process receives the signal and sub-processes hang. Very likely what's happening.

    Proposed Solution:

    • Check the programs documentation on how it's properly started and stopped. ctrl-c seems not to be the proper way.

    • Wrap the program with a docker-entrypoint.sh bash script that blocks the container process and is able to catch ctrl-c. This bash example should help: https://rimuhosting.com/knowledgebase/linux/misc/trapping-ctrl-c-in-bash

    • After catching ctrl-c invoke the proper shutdown method for ipython notebook.