Laravel Horizon with Docker

We simply pass the command to the Docker container and let S6 Overlay monitor the process.

Important concepts

  1. In most cases, you probably want to run this as a separate container from your web container
  2. If you want to run this in the same container, then you should create a custom S6 script to bring the service up and to monitor it
  3. Ensure that you have your .env configured correctly to authenticate with Redis
  4. Ensure Redis is running before you attempt to connect Horizon to Redis

Task Command

php artisan horizon

Example Docker Compose File

version: '3'services:  php:    image: my/laravel-app    environment:      PHP_POOL_NAME: "my-app_php"  redis:    image: redis:6    command: "redis-server --appendonly yes --requirepass redispassword"  horizon:    image: my/laravel-app    # Switch to "webuser" before running `php artisan`    # Declare command in list manner for environment variable expansion    command: ["su", "webuser", "-c", "php artisan horizon"]    environment:      PHP_POOL_NAME: "my-app_horizon"