Hej there,
For some days I try to find a good solution for my Laravel app. I am using docker and docker compose to organise my stack and have splitted it into the following services:
- Nginx for serving the requests
- PHP-FPM for processing requests to the Laravel app passed from Nginx
- PHP-FPM for handling the queue of the Laravel app
- PHP-FPM for handling the schedule of the Laravel app
- MariaDB as database
The services with PHP-FPM use the same customized docker image that adds the necessary files for the Laravel app.
My problem is that I am not sure how I should provide the files of my Laravel app to the services. I can think of two ways:
- Copy the files in the customized Dockerfile. With this approach I can deploy my app via a custom registry and start the queue and the schedule by changing the entrypoint in the
docker-compose.yml
. Downside is that I do not know how Nginx should access the files inside the container, especially the static assets. Also this makes things harder while in development. - Bind the files as volume into the container. This solves (almost) all downside problems of the first approach but I cannot think about a good solution for starting the queue and the schedule workers (in a Dockerish way).
I would be so thankful for any help and useful advice. After reading a lot of questions here at SO and other blog posts and watching some YouTube videos I am very, very confused.
2
Answers
you can install supervisor in Dockerfile and run necessary services inside it: cron, php-fpm, queue.
Dockerfile
supervisord.conf
crontab
In a dockerish way what you can do is separate out the services in a different containers so that the queue and cron jobs does not affect your base main application.
You can take a look at a docker-compose file for reference
Here, first we create the laravel application image and then use the same image to run the queue worker and task scheduler into a separate container. Your nginx service will be serving only from the laravel-app container.