Laravel
Horizon
Laravel Horizon with Docker
We simply pass the command to the Docker container and Laravel will start the Horizon process.
php artisan horizon
Important concepts
Want to skip the setup? Spin Pro handles Laravel schedulers on your VPS with Docker and zero-downtime deployments—all configured for you.
- In most cases, you probably want to run this as a separate container from your web container
- If you're using
fpm-apacheorfpm-nginx, might need to set the stop signal toSIGTERMfor a graceful shutdown (see this PR for more details why) - Be sure to set the health check
- Ensure that you have your
.envconfigured correctly to authenticate with Redis - Ensure Redis is running before you attempt to connect Horizon to Redis
- 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.
Run it with Docker
Notice we're calling the artisan command explicitly with the full path (
/var/www/html/artisan). This is because we need to run the command from the context of the container.Example & Simplified Docker Compose File
compose.yml
services:
php:
image: my/laravel-app
redis:
image: redis:6
command: "redis-server --appendonly yes --requirepass redispassword"
horizon:
image: my/laravel-app
command: ["php", "/var/www/html/artisan", "horizon"]
stop_signal: SIGTERM # Set this for graceful shutdown if you're using fpm-apache or fpm-nginx
healthcheck:
# This is our native healthcheck script for Horizon
test: ["CMD", "healthcheck-horizon"]
start_period: 10s