I have a laravel 9 application that I want to deploy to AWS ECS. The application uses redis for queue and I have installed horizon. I also installed Supervisor in the docker container but once I deploy my application and start up supervisor in my startup.sh script, my app is never reachable and I notice that both queue worker and horizon start and then exit.
Here's the dockerfile I am working with
FROM php:8.1.4-fpm-alpine3.14
RUN apk update
RUN apk add --no-cache git libzip-dev zip unzip php8-exif supervisor
RUN mkdir -p /usr/src/php/ext/redis; \
curl -fsSL https://pecl.php.net/get/redis --ipv4 | tar xvz -C "/usr/src/php/ext/redis" --strip 1; \
docker-php-ext-install redis;
RUN docker-php-ext-configure pcntl --enable-pcntl \
&& docker-php-ext-install \
pcntl
RUN docker-php-ext-install pdo pdo_mysql zip exif \
&& curl -sS https://getcomposer.org/installer | php -- \
--install-dir=/usr/local/bin --filename=composer
WORKDIR /var/www/html
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
COPY . .
RUN chown -R www-data:www-data /var/www/html
RUN composer install --ignore-platform-req=ext-pcntl
RUN chmod 544 startup.sh
ENTRYPOINT ["./startup.sh"]
this is my supervisord.conf file content
[supervisord]
nodaemon=true
loglevel=debug
logfile=/var/www/html/storage/logs/supervisord.log
user=root
[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/html/artisan queue:work redis --sleep=3 --tries=3 --max-time=3600
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
user=root
numprocs=8
redirect_stderr=true
stdout_logfile=/var/www/html/storage/logs/worker.log
stopwaitsecs=3600
[program:horizon]
process_name=%(program_name)s
command=php /var/www/html/artisan horizon
autostart=true
autorestart=true
user=root
redirect_stderr=true
stdout_logfile=/var/www/html/storage/logs/horizon.log
stopwaitsecs=3600
and my startup.sh script content is
#!/bin/sh
/usr/bin/supervisord
php artisan migrate
php artisan db:seed
php artisan config:cache
php artisan route:cache
php artisan serve --host=0.0.0.0 --port 80
If I comment out /usr/bin/supervisord and deploy to aws ecs, I am able to reach my app again. So what exactly am I doing wrong with the supervisor that is causing it to break my app and how can I fix it?