Should I run the init process inside a Docker container or not? [closed] Should I run the init process inside a Docker container or not? [closed] docker docker

Should I run the init process inside a Docker container or not? [closed]


As often there is maybe no absolute answer on how to handle these cases. Can you share some experiences or more insights about this topic? For me both approached seem legit.

Spot on. There is no absolute answer to this question.

Now, having said that, I think that there are substantial advantagesto the single-process-per-container model, because that reallyencourages you to create containers that are composable (like legoblocks: you can put them together in different combinations to solve aproblem) and that are scalable (you can spin up more instances of aparticular service without too much effort). By not doing crazythings like running an ssh daemon inside your container, you arediscouraged from editing things "in place" and will -- hopefully -- bemore likely to rely on Dockerfiles to generate your images, whichleads to a much more robust, reproducible process.

On the other hand, there are some applications that don't lendthemselves well to this model. For example, if you have anapplication that forks lots of child processes and doesn't properlywait() for them, you end up with a collection of zombie processes.You can run a full-blown init process to solve this particularproblem, or you can run something simple likethis (disclaimer: I wrote that) orthis.

Some applications are just really tightly coupled, and while it'spossible to run them in separate containers through liberalapplication of Docker volumes and --net=container:..., it's easierjust to let them run in the same container.

Logging in Docker is particular challenging. Running some sort oflog collector inside a container along with your application can beone solution to that problem, but there are other solutions, too.Logspout is an interestingone, but I have also been looking at running systemd insidecontainers in order to make use of journald for logging. So, whileI am still running one application process per container, I alsohave an init process, and a journald process.

So, ultimately, it really depends on the situation: both on your needsand the needs of the particular application you are trying to run.Even in situations where a single process per container isn'tpossible, designing containers to offer a single service stillconfers many of the advantages I mentioned in the first paragraph.