DEV Community

Muneeb Ur Rehman
Muneeb Ur Rehman

Posted on

14 3

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

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (3)

Collapse
 
dimoncamelot profile image
Dmitriy Filippov

Thank you so much!

Collapse
 
lacksinho profile image
Lackson David

I have followed all steps and the supervisor is up running but jobs are still fired.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vmrcunhq0i7axcheqgve.png)
Enter fullscreen mode Exit fullscreen mode
👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay