Docker Community Forums

Share and learn in the Docker community.

Autostart mutliple services (nginx, php-fpm)

Hi all,
I have one question regarding of what is the best practice when comes to starting multiple services in one container. For example; I have one Ubuntu based Dockerfile in which I have to install Grav. In order this to work; I need to have nginx and php-fpm services running when image is started.

Currently, I am using monit with such configuration that it starts both nginx and php-fpm. Monit itself is called at the end of the Dockerfile as:

# Run services via Monit daemon
ENTRYPOINT service monit start && /bin/bash

It works, but I am not sure is this the ‘Docker way’ and if not; shall I take different approach?

Thank you in advance.

Best regards

Hi :slight_smile:

The docker way would be to split the services up, but if you want to put it all in 1 container, it will work.
I think most people uses supervisor, you can check out my example here: CentOS 7 systemd

Thanks - if I go with this ‘split’ approach, what I would need to do then? Is it something like:

  1. create one image to host file system (site)
  2. one image to run nginx
  3. one image to run PHP-FPM
  4. ‘compose’ to sync everything?

Pardon me, but I am newbie in Docker :frowning:

Thanks!

In this case I would say that you are doing it right. I would consider the Nginx/PHP/Grav CMS to be one entity. Splitting them would not make any difference. You can run a pure Nginx and route it to the PHP/Grav-instance if you want, but more separation than that is not needed in this case. Then it is up to compose to make sure that you have your PHP/Grav-container up and running before starting Nginx.

I always wrap my entrypoint in a entrypoint.sh file that I add. That way, if I need to test something else, like running it in debug mode, I can easily mount a new entrypoint.sh file when starting the container.

So, I shall try to it the Docker way, using 2 instances: one with Nginx and another with PHP/Grav?

Thanks!

1 Like