Laravel queues with supervisor - Docker Configuration

muneebkh2

Muneeb Ur Rehman

Posted on May 26, 2022

Laravel queues with supervisor - Docker Configuration

I am writing this blog for those people who are facing difficulties for setting up the queues with supervisor using docker.

So we'll going to create a separate service of docker for supervisor to do better performance.

first we need to configure the main docker-compose.yml :

supervisor:
    build:
      context: .
      dockerfile: {path to file}/supervisor.dockerfile
    container_name: supervisor
    volumes:
      - ./src:/var/www/html
    networks:
      - laravel

Enter fullscreen mode Exit fullscreen mode

then need to create a separate dockerfile for supervisor supervisor.dockerfile

FROM php:7.4-fpm-alpine // I'm using 7.4 you can use php-version as per your application.

RUN docker-php-ext-install pdo pdo_mysql

RUN apk update && apk add --no-cache supervisor

RUN mkdir -p "/etc/supervisor/logs"

COPY {path to file}/supervisord.conf /etc/supervisor/supervisord.conf

CMD ["/usr/bin/supervisord", "-n", "-c",  "/etc/supervisor/supervisord.conf"]

Enter fullscreen mode Exit fullscreen mode

after that we need to create a supervisord.conf configuration file and set the logs directory and etc... in it.

[supervisord]
logfile=/etc/supervisor/logs/supervisord.log ; main log file; default $CWD/supervisord.log
logfile_maxbytes=5MB         ; max main logfile bytes b4 rotation; default 50MB
logfile_backups=10           ; # of main logfile backups; 0 means none, default 10
loglevel=info                ; log level; default info; others: debug,warn,trace
pidfile=/tmp/supervisord.pid ; supervisord pidfile; default supervisord.pid
nodaemon=false               ; start in foreground if true; default false
minfds=1024                  ; min. avail startup file descriptors; default 1024
minprocs=200                 ; min. avail process descriptors;default 200

[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[supervisorctl]
serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL  for a unix socket

[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/html/artisan queue:work
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
numprocs=1
redirect_stderr=true
stdout_logfile=/var/www/html/storage/logs/worker.log
stopwaitsecs=3600
stdout_logfile_maxbytes=5MB
Enter fullscreen mode Exit fullscreen mode

and that's it.

now run & rebuild the docker container and it's worked like a boom 💥

Thanks for reading.

** If you have any question so you can ask in comment section

💖 💪 🙅 🚩
muneebkh2
Muneeb Ur Rehman

Posted on May 26, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related