Docker not responding to CTRL + C in terminal

Currently there is a problem with Docker; I use it to run an image that starts ipython laptop at startup. I want to make some changes for the ipython laptop itself, so I need to close it after starting.

However, pressing CTRL + C on the terminal simply enters ā€œ^ Cā€ as a string. There seems to be no real way to use CTRL + C to actually close the ipython laptop instance.

Does anyone have any clues as to what might cause this, or know any solutions for it?

+7
linux docker ipython-notebook centos
source share
3 answers

This post offers CTRL-Z as a workaround to send the process to the background and then kill the process by its process id: Cannot kill Python script using Ctrl-C

Possible problems:

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

  • There are background processes that are not managed correctly. Only the main process receives the signal and subprocesses. Very likely what is happening.

Proposed Solution:

  • Check the documentation of how it was started and stopped. ctrl-c seems not correct.

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

  • After you press ctrl-c, run the appropriate shutdown method for the ipython laptop.

+4
source share

The problem is that Ctrl-C sends a signal to the top-level process inside the container, but this process does not necessarily respond as you expected. The top-level process has identifier 1 inside the container, which means that it does not receive the default signal handlers that processes usually have. If the top-level process is a shell, then it can receive a signal through its own handler, but does not pass it to a command that runs in the shell. Details are explained here . In both cases, the docker container works as if it simply ignores Ctrl-C.

If you create your own images, the solution should start a minimal init process, such as tini or dumb-init , like a top-level process inside a container.

+2
source share
Answer

@maybeg already very well explains why this could happen.

As for stopping the container without response, another solution is to simply issue docker stop <container-id> to another terminal. Unlike CTRL-C , docker stop does not send a SIGINT signal, but SIGTERM, to which a process can respond differently.

Usage: stop docker [OPTIONS] CONTAINER [CONTAINER ...]

Stop the running container by sending SIGTERM and then SIGKILL after the grace period

If this fails, use docker kill <container-id> , which immediately sends SIGKILL.

0
source share

All Articles