Laravel Horizon with Docker

We simply pass the command to the Docker container and Laravel will start the Horizon process.

Usual Laravel Horizon Command

php artisan horizon

Important concepts

  1. In most cases, you probably want to run this as a separate container from your web container
  2. If you're using fpm-apache or fpm-nginx, might need to set the stop signal to SIGTERM for a graceful shutdown (see this PR for more details why)
  3. Be sure to set the health check
  4. Ensure that you have your .env configured correctly to authenticate with Redis
  5. Ensure Redis is running before you attempt to connect Horizon to Redis
  6. 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

Example Docker Compose File

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

Get Up and Running The Easy Way

We do all the heavy lifting for you with Spin Pro. It's as easy as selecting it in a menu and we'll configure everything else for you. Learn how easy it is to get up and running with Horizon on Spin Pro.

Learn more about Laravel Horizon + Spin Pro →