Explore Courses Blog Tutorials Interview Questions
0 votes
in DevOps and Agile by (29.3k points)

 Do I need to use separate Docker containers for my complex web application or I can put all required services in one container? Could anyone explain to me why I should divide my app to many containers (for example php-fpm container, MySQL container, mongo container) when I can install and launch all stuff in one container?

1 Answer

0 votes
by (50.2k points)

While working with Docker, Docker will replace your PID 1(process id 1 where the init system lives ) with the command you specify in the CMD(and ENTRYPOINT) directive in your Dockerfile. Your container lives and dies depends on whatever process is present pid1. Incidentally, this is why you need to jump through hoops to start services and run cron jobs. This is very important in understanding the motivation for doing things. So you could figure out how to run all of those services in one container. But now you know that how docker replaces pid 1 with whatever command you specify in CMD (and ENTRYPOINT) in your Dockerfiles if in case you are running apps in their containers for their future purposes you can let them work with the help of container interlinking. Container linking has been deprecated in favor of regular ole container networking, which is much tougher, the idea being that you simply join your separate application containers to the same network so they can talk to one another

On a side note, it is much cleaner and better to maintain separate containers instead of linking and messing all the containers.

Browse Categories