I'm building a Laravel image which runs with the user backend
that have the id 1000
. This user should allow me to prevent the following error:
File could not be opened in append mode: failed to open stream: Permission denied
The problem's that when I run the supervisor I get this error:
IOError: [Errno 13] Permission denied: '/var/log/supervisord.log'
This is my Dockerfile:
FROM php:8.1.10-fpm-buster
WORKDIR /var/www
RUN docker-php-ext-install bcmath pdo_mysql
RUN apt-get update
RUN apt-get install -y git zip unzip netcat
# Supervisor
RUN apt-get install -y supervisor
# Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
# Configurations
COPY docker/php/config/supervisor.conf /etc/supervisord.conf
COPY docker/php/config/php.ini /usr/local/etc/php/conf.d/app.ini
# Log file
RUN mkdir /var/log/php
RUN touch /var/log/php/errors.log && chmod 777 /var/log/php/errors.log
# Deploy
COPY /docker/php/scripts/start.sh /start.sh
RUN chmod x /start.sh
# Add user for laravel application
RUN groupadd -g 1000 backend
RUN useradd -u 1000 -ms /bin/bash -g backend backend
# Copy existing application directory contents
COPY . /var/www
# Copy existing application directory permissions
COPY --chown=backend:backend . /var/www
USER backend
EXPOSE 9000
ENTRYPOINT /start.sh
This is my docker-compose file:
version: '3.9'
services:
php:
container_name: ${APP_NAME}_app
#user: ${CURRENT_UID}
restart: always
build:
context: .
dockerfile: ./docker/php/Dockerfile
volumes:
- ./src:/var/www
env_file: .env
And this is the entrypoint script:
#!/bin/bash
# Run composer install
composer install
# Generate key and clear cache
php artisan key:generate
php artisan config:clear
php artisan config:cache
# Wait db connection
until nc -z ${DB_HOST} ${DB_PORT}; do sleep 1; echo "Wait database ..."; done
# Execute migrations
php artisan migrate --seed
/usr/bin/supervisord -c /etc/supervisord.conf
Last but not least, the supervisor.conf:
[supervisord]
nodaemon=true
loglevel = info
logfile=/var/log/supervisord.log
pidfile=/var/run/supervisord.pid
[group:laravel-worker]
priority=999
programs=laravel-app,laravel-schedule,laravel-notification,laravel-queue
[program:laravel-app]
priority=5
autostart=true
autorestart=true
stderr_logfile_maxbytes=0
stdout_logfile_maxbytes=0
command=/usr/local/sbin/php-fpm -R
stderr_logfile=/var/log/php/php-error.log
stdout_logfile=/var/log/php/php-access.log
[program:laravel-schedule]
numprocs=1
autostart=true
autorestart=true
redirect_stderr=true
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/artisan schedule:run
stdout_logfile=/var/log/php/schedule.log
[program:laravel-notification]
numprocs=1
autostart=true
autorestart=true
redirect_stderr=true
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/artisan notification:worker
stdout_logfile=/var/log/php/notification.log
[program:laravel-queue]
numprocs=5
autostart=true
autorestart=true
redirect_stderr=true
process_name=%(program_name)s_%(process_num)02d
stdout_logfile=/var/log/php/worker.log
command=php /var/www/artisan queue:work sqs --sleep=3 --tries=3
Is there any way to fix the permission issue?
CodePudding user response:
This is my supervisord.conf as an example.
I am always adding user=root
row. And never got a permission error.
[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/artisan queue:work --sleep=3 --tries=3
autostart=true
autorestart=true
user=root
numprocs=1
redirect_stderr=true
CodePudding user response:
this issue because using USER backend
in Docker file, you need to configure supervisor for using same user in Docker file user=backend