Laravel Queue with Docker
All you need to do is pass the Laravel Queue command to the container and S6 will automatically monitor it for you.
Important concepts
- It's usually best to run the queue as a separate container (but using the same image)
- Notice we're using the same
my/laravel-app
image for both the PHP and Queue services. This is a common practice to keep the image consistent. - You can do cool things with
PHP_FPM_POOL_NAME
to separate the task from the main PHP pool. This is helpful when debugging or monitoring the task. - If you need to run the queue in the same container, you might want to look into writing your own S6 Overlay script to manage and monitor multiple processes in one container.
Task Command
php artisan queue:work --tries=3
Example & Simplified Docker Compose File
version: '3'
services:
php:
image: my/laravel-app
environment:
PHP_FPM_POOL_NAME: "my-app_php"
queue:
image: my/laravel-app
command: ["php", "/var/www/html/artisan", "queue:work", "--tries=3"]
environment:
PHP_FPM_POOL_NAME: "my-app_queue"