Avoid docker exec zombie processes when connecting to containers via bash

1.7k views Asked by At

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?

1

There are 1 answers

0
avivr On

One way is to make sure the linux init process runs in your container. In recent versions of docker there is an --init option to docker run that should do this. This uses tini to run init 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).