John Davidson

Should you put PHP + Cron in the same docker container?

0 comments
Message:


I am fairly new to docker and I am still trying to figure out what the best practices and conventions are.


One thing I see over and over again is: "each container should be responsible for just a single process".


I am coming from the average LAMP stack. So one apache server is serving multiple websites running on php, and they all have some cronjobs running (combined in a single cron-file).


So, the docker way...
A single container for mysql.
A single container for php+apache (can access the mysql container via the 'docker-network'.


But now the cronjobs. I see people saying: you should make a seperate container for that. But, to my knowning, there is no way the cron-container would be able to access the php-command from the php+apache container.


What is the convention here? I feel like I should put the cron in the php+apache container, and just run it as an additional process in that container. Is that correct?


Next to this: should every website have its own docker php+apache+cron container? Or is it 'allowed' to bundle them together?


Any advice? Thanks!



My Answer:
it is generally not recommended to put PHP Cron in the same docker container.

The reason for this is that docker containers are meant to be lightweight and isolated, with each container serving a specific purpose. By combining PHP and Cron in the same container, you are mixing concerns and potentially creating a monolithic container that is harder to manage and scale.

Instead, it is recommended to create separate containers for PHP and Cron, each serving their own specific purpose. This allows for better separation of concerns, easier management, and scalability. You can then use docker-compose or another orchestration tool to manage the communication between the containers.

Overall, it is best practice to follow the principle of single responsibility and keep your containers focused on one specific task.

Rate this post

4 of 5 based on 5010 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us