├── .env.example ├── Dockerfile ├── README.md ├── docker-compose.example.yml └── supervisord.conf /.env.example: -------------------------------------------------------------------------------- 1 | APP_ROOT=app_root_directory_inside_container 2 | QUEUE_CONNECTION=database # this is set to `sync` in the .env file Laravel provides 3 | QUEUE_OPTIONS="--queue=some_queue --sleep=3 --tries=3" 4 | NUM_PROCS=4 -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM php:7.4-cli 2 | 3 | LABEL author="redditsaved" 4 | 5 | ENV APP_ROOT=/home/app QUEUE_DRIVER=database NUM_PROCS=4 OPTIONS= 6 | 7 | ADD supervisord.conf /etc/ 8 | 9 | RUN docker-php-ext-install pdo_mysql \ 10 | && docker-php-ext-install bcmath \ 11 | && apt-get update \ 12 | && apt-get install -y --no-install-recommends supervisor 13 | 14 | CMD ["supervisord", "-c", "/etc/supervisord.conf"] 15 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## laravel-supervisord 2 | This is the Dockefile for the Docker image laravel-supervisord hosted on https://hub.docker.com/r/redditsaved/laravel-supervisord. 3 | 4 | It has been structured in such way as to be used with `docker-compose`. The `supervisord.conf` uses the following containers environment variables to start and manage Laravel queue workers: 5 | 6 | * APP_ROOT: this is the root directory of your Laravel application inside the container (mount your local Laravel app directory to the container). Specifically, `artisan` must be located in this directory. 7 | * QUEUE_DRIVER: this is the driver of your [Laravel queues](https://laravel.com/docs/7.x/queues#driver-prerequisites). 8 | * OPTIONS: these are arguments sent to `php artisan queue:worker QUEUE_DRIVER`, e.g. `php artisan queue:worker database --sleep=3 --tries=3`. 9 | * NUM_PROCS: this is the number of workers that `supervisord` must create to handle jobs. 10 | 11 | In the repo you can find also an example `docker-compose.yml` with an example `.env` file. 12 | -------------------------------------------------------------------------------- /docker-compose.example.yml: -------------------------------------------------------------------------------- 1 | version: '3.2' 2 | services: 3 | supervisor: 4 | container_name: supervisor 5 | image: redditsaved/laravel-supervisord:latest 6 | restart: unless-stopped 7 | environment: 8 | - APP_ROOT=${APP_ROOT} 9 | - QUEUE_DRIVER=${QUEUE_CONNECTION} 10 | - OPTIONS=${QUEUE_OPTIONS} 11 | - NUM_PROCS=${NUM_PROCS} 12 | volumes: 13 | - laravel_directory:${APP_ROOT} 14 | network_mode: host 15 | -------------------------------------------------------------------------------- /supervisord.conf: -------------------------------------------------------------------------------- 1 | [supervisord] 2 | nodaemon=true 3 | [program:laravel-worker] 4 | process_name=%(program_name)s_%(process_num)02d 5 | command=php %(ENV_APP_ROOT)s/artisan queue:work %(ENV_QUEUE_DRIVER)s %(ENV_OPTIONS)s 6 | stdout_logfile=%(ENV_APP_ROOT)s/storage/logs/worker.log 7 | autostart=true 8 | autorestart=true 9 | numprocs=%(ENV_NUM_PROCS)s 10 | redirect_stderr=true 11 | stopwaitsecs=3600 12 | --------------------------------------------------------------------------------