0

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!

9
  • You should separate it. If the PHP container dies, all cronjobs are dead. Commented Aug 30, 2022 at 16:41
  • But why should it be able to access the php-command from the php+apache container? Why can't it access its own php? Commented Aug 30, 2022 at 16:43
  • @MarkusZeller The cronjobs will execute some php scripts. So it kind of makes sense if the php container dies the cronjobs can't be executed. Commented Aug 30, 2022 at 17:05
  • @YourCommonSense In that case I would have cron+php container next to my php+apache container? What benefit does this have then over having a php+apache+cron container? Commented Aug 30, 2022 at 17:06
  • 1
    Then ask yourself why did you move mysql container away first. It uses the same Debian/Ubuntu system as PHP-Apache container does. Why cannot mysql use the same system then? How having same piece of software in two containers can justify anything? Commented Aug 30, 2022 at 17:12

1 Answer 1

0

There is no right or wrong answer here, it really depends on your specific needs and preferences. If you want to keep your containers small and focused on a single task, then you would want to create a separate container for your cronjobs. However, if you don't mind having a larger container that handles multiple tasks, then you can definitely put your cronjobs in the same container as your PHP + Apache server.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.