By default, Docker sends a TERM signal to a container when you want to
stop it. When runit is used as init inside a Docker container, this
directly kills the runsvdir process, without really cleaning up any
In newer Docker version you can configure STOPSIGNAL inside your
Dockerfile to configure for example for Docker to send HUP to
runsvdir. But the issue is that because runsvdir exists immediately
after sending TERM to children, Docker kills the whole container
before really leaving to children to terminate gracefully.
So there would be two things to improve behavior inside Docker containers here:
First, there could be an option to set which signal is used as current
HUP signal. This could make it work in older Docker versions, as one
could for example run runsvdir --hup-signal=TERM to override behavior
of TERM signal.
Second, after it gets HUP signal, runsvdir could wait for all children
to finish before existing itself. (If they do not finish in reasonable
time, Docker will kill anyway all processes with KILL.)