Laravel Horizon with Docker
We simply pass the command to the Docker container and let S6 Overlay monitor the process.
Important concepts
- In most cases, you probably want to run this as a separate container from your web container
- Ensure that you have your
.env
configured correctly to authenticate with Redis - Ensure Redis is running before you attempt to connect Horizon to Redis
- 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 horizon 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 horizon
Example Docker Compose File
version: '3'
services:
php:
image: my/laravel-app
environment:
PHP_FPM_POOL_NAME: "my-app_php"
redis:
image: redis:6
command: "redis-server --appendonly yes --requirepass redispassword"
horizon:
image: my/laravel-app
command: ["php", "/var/www/html/artisan", "horizon"]
environment:
PHP_FPM_POOL_NAME: "my-app_horizon"