Like most docker users, I periodically need to connect to a running container and execute various arbitrary commands via bash.
I'm using 17.06-CE with an ubuntu 16.04 image, and as far as I understand, the only way to do this without installing ssh into the container is via docker exec -it <container_name> bash
However, as is well-documented, for each bash shell process you generate, you leave a zombie process behind when your connection is interrupted. If you connect to your container often, you end up with 1000s of idle shells -a most undesirable outcome!
How can I ensure these zombie shell processes are killed upon disconnection -as they would be over ssh?
One way is to make sure the linux
init
process runs in your container. In recent versions of docker there is an--init
option todocker run
that should do this. This uses tini to runinit
which can also be used in previous versions.Another option is something like the phusion-baseimage project that provides a base docker image with this capability and many others (might be overkill).