if an application needs several containers running on the same host, why not just make a single container with everything you need?

8/2/2018

I started working on kubernetes. I already worked with single container pods. Now i want to working on multiple container pod. i read the statement like

if an application needs several containers running on the same host, why not just make a single container with everything you need?

means two containers with single IP address. My dought is, in which cases two or more containers uses same host?

Could you please anybody explain me above scenario with an example?

-- gayathri
google-kubernetes-engine
kubernetes

3 Answers

8/5/2018

I would say segregating responsibilities can be a boon. Maintenance is whole lot easier this way. A container can have a single entrypoint and a pod's health is checked via that main process in the entry point. If your front end (say Java over Tomcat ) application is working fine but database is not working (although one must never use production database in container), you will not get the feedback that u might get when they are different containers. Also, one of the best part of docker images are they are available as different modules and maintenance is super easy that way.

-- Narendra
Source: StackOverflow

8/2/2018

This is called "multiple processes per container". https://docs.docker.com/config/containers/multi-service_container/

t's discussed on the internet many times and it has many gotchas. Basically there's not a lot of benefit of doing it.

Ideally you want container to host 1 process and its threads/subprocesses.

So if your database process is in a crash loop, let it crash and let docker restart it. This should not impact your web container.

Also putting processes in separate containers lets you set separate memory/CPU limits so that you can set different limits for your web container and database container.

That's why Kubernetes exposes POD concept which lets you run multiple containers in the same namespace. Read this page fully: https://kubernetes.io/docs/concepts/workloads/pods/pod/

-- AhmetB - Google
Source: StackOverflow

8/3/2018

Typically it is recommended to run one process in a docker container. Although it is very much possible to run multiple processes in a container it is discouraged more on the basis of application architecture and DevOps perspective rather than technical reasons.

Following discussion gives a better insight into this debate: https://devops.stackexchange.com/questions/447/why-it-is-recommended-to-run-only-one-process-in-a-container

When one runs multiple processes from different packages/tools in the same docker it could run into dependency and upgradability issues that docker meant to solve in the first place. Nevertheless, for many applications, it makes much sense to scale and manage application in blocks rather than individual components, sometimes it makes life bit easy. So PODs are basically a balance between the two. It gives the isolation for each process for better service manageability and yet groups them together so that the application as a whole can be better managed.

-- Murli
Source: StackOverflow