Why can't I CTRL-C a sleep infinity in docker when it runs as PID 1 Why can't I CTRL-C a sleep infinity in docker when it runs as PID 1 bash bash

Why can't I CTRL-C a sleep infinity in docker when it runs as PID 1


Would this be of any use? https://www.fpcomplete.com/blog/2016/10/docker-demons-pid1-orphans-zombies-signals

Basically the problem is process number 1. Linux/unix kernels are reluctant to signal that process the regular way, as it is supposed to be init. If init process dies, the system issues a panic immediately and reboots. If your process 1 does not have a handler to a signal, the signal just gets dropped. Sleep does not have handlers for any signals but you can build one to bash script.

Basically what you need to do is use exec form in your dockerfile, and split your sleep infinity into a loop as bash traps do not get triggered while shell is executing a command. This sends a signal to the running process 1 and catches it:

Dockerfile:

FROM ubuntuADD foo.sh /tmpRUN ["/tmp/foo.sh"]

foo.sh:

#!/bin/bashtrap "echo signal;exit 0" SIGINT while :do    sleep 1done

This will react to docker kill --signal=SIGINT.