Docker - unable to run supervisor - php

I try to install supervisor on my local docker container where I run php8.1 and laravel 9.
But I have following error:
'PermissionError: [Errno 13] Permission denied: '/var/log/supervisor/supervisord.log'
This is my config:
supervisor.conf
[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
php dockerfile:
FROM php:8.1.13-fpm
RUN apt-get update && apt-get install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
nano \
libxslt1.1 \
libxslt1-dev \
unzip \
git \
gnupg \
libpq-dev \
libzip-dev \
iputils-ping \
supervisor \
&& docker-php-ext-install zip \
gd \
mysqli pdo pdo_mysql \
&& docker-php-ext-enable pdo_mysql \
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-configure intl \
RUN echo "memory_limit='512M'" >> /usr/local/etc/php/conf.d/php-extra.ini;
ENV PHP_IDE_CONFIG "serverName=new_app"
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer --version=2.3.8 && chmod +x /usr/bin/composer
# Set timezone
RUN rm /etc/localtime \
&& ln -s /usr/share/zoneinfo/Europe/Warsaw /etc/localtime \
&& "date" \
&& printf '[PHP]\ndate.timezone = "Europe/Warsaw"\n' > /usr/local/etc/php/conf.d/tzone.ini \
RUN usermod -aG docker $USER
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/supervisord.conf"]
WORKDIR /var/www/html
How can I fix it?
Regards.

1.
i saw these in your dockerfile, your file does not match,
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/supervisord.conf"]
i suggest to change to below:
COPY supervisord.conf /etc/supervisor/supervisord.conf
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/supervisord.conf"]
2.
Add this to your dockerfile, to replace the original line, and try again. Good luck
RUN usermod -aG docker $USER &&\
mkdir -p /var/www/html/storage/logs &&\
touch /var/www/html/storage/logs/worker.log

Related

Docker / PHP / Apache - File permissions lost when created inside container

i'm trying to set up a docker app with Apache and Php stack.
But when i create a new file inside my project container, the permissions losted because root user is connected by default.
How can I connect my host user ?
docker-compose.yml
version: '3'
services:
web:
container_name: web
build:
context: docker/web
volumes:
- ./app/:/var/www/app
- ./docker/web/apache/log:/var/log/apache2/app
working_dir: /var/www/app
ports:
- 80:80
dockerfile
FROM php:7.4-apache
ENV APACHE_DOCUMENT_ROOT /var/www
RUN apt-get update && apt-get install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
libzip-dev \
git \
zip \
unzip \
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install -j$(nproc) gd \
&& docker-php-ext-install zip pdo pdo_mysql opcache \
&& apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN rm /etc/localtime
RUN ln -s /usr/share/zoneinfo/Europe/Paris /etc/localtime
RUN "date"
RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf
RUN sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf
COPY php/php.ini /usr/local/etc/php/conf.d/app.ini
COPY apache/app.conf /etc/apache2/sites-available/000-default.conf
RUN groupadd dev -g 1000
RUN useradd dev -g dev -d /home/dev -m
RUN echo '%dev ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
I tried to create a dev user in my Dockerfile but not working.
And how about this?
# Add www-data to the '1000-group'
RUN usermod -u 1000 www-data
I solved the problem by adding my dev user to sudoers and then running apache2ctl in sudo.
FROM php:7.4-apache
RUN apt-get update && apt-get install -y \
sudo \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
libzip-dev \
git \
zip \
unzip \
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install -j$(nproc) gd \
&& docker-php-ext-install zip pdo pdo_mysql opcache \
&& apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN rm /etc/localtime
RUN ln -s /usr/share/zoneinfo/Europe/Paris /etc/localtime
RUN "date"
RUN sed -ri -e 's!/var/www/html!/var/www!g' /etc/apache2/sites-available/*.conf
RUN sed -ri -e 's!/var/www/!/var/www!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf
COPY php/php.ini /usr/local/etc/php/conf.d/app.ini
COPY apache/app.conf /etc/apache2/sites-available/000-default.conf
RUN groupadd dev -g 1000
RUN useradd dev -g dev -d /home/dev -m
RUN echo '%dev ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
USER dev:dev
CMD ["sudo", "/usr/sbin/apache2ctl", "-D", "FOREGROUND"]

Migrate to docker desktop 2.2 generate acl errors

Description:
One of my team member has migrate docker desktop to version 2.2.
Since, the php service won't start due to setfacl command from an entrypoint.sh.
Context:
We are working on a api-platform project in version 2.4.7.
Php Dockerfile:
# the different stages of this Dockerfile are meant to be built into separate images
# https://docs.docker.com/develop/develop-images/multistage-build/#stop-at-a-specific-build-stage
# https://docs.docker.com/compose/compose-file/#target
# https://docs.docker.com/engine/reference/builder/#understand-how-arg-and-from-interact
ARG PHP_VERSION=7.3
ARG NGINX_VERSION=1.15
ARG VARNISH_VERSION=6.0
# "php" stage
FROM php:${PHP_VERSION}-fpm-alpine AS api_platform_php
RUN apk add --no-cache --virtual .build-deps $PHPIZE_DEPS icu-dev openldap-dev && \
docker-php-ext-install ldap && \
docker-php-ext-enable ldap && \
apk del .build-deps
# persistent / runtime deps
RUN apk add --no-cache \
acl \
file \
gettext \
git \
;
ARG APCU_VERSION=5.1.17
RUN set -eux; \
apk add --no-cache --virtual .build-deps \
$PHPIZE_DEPS \
icu-dev \
libzip-dev \
zlib-dev \
; \
\
docker-php-ext-configure zip --with-libzip; \
docker-php-ext-install -j$(nproc) \
intl \
pdo_mysql \
zip \
; \
pecl install \
apcu-${APCU_VERSION} \
; \
pecl clear-cache; \
docker-php-ext-enable \
apcu \
opcache \
; \
\
runDeps="$( \
scanelf --needed --nobanner --format '%n#p' --recursive /usr/local/lib/php/extensions \
| tr ',' '\n' \
| sort -u \
| awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
)"; \
apk add --no-cache --virtual .api-phpexts-rundeps $runDeps; \
\
apk del .build-deps
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
RUN ln -s $PHP_INI_DIR/php.ini-production $PHP_INI_DIR/php.ini
COPY docker/php/conf.d/api-platform.ini $PHP_INI_DIR/conf.d/api-platform.ini
# https://getcomposer.org/doc/03-cli.md#composer-allow-superuser
ENV COMPOSER_ALLOW_SUPERUSER=1
# install Symfony Flex globally to speed up download of Composer packages (parallelized prefetching)
RUN set -eux; \
composer global require "symfony/flex" --prefer-dist --no-progress --no-suggest --classmap-authoritative; \
composer clear-cache
ENV PATH="${PATH}:/root/.composer/vendor/bin"
WORKDIR /srv/api
# build for production
ARG APP_ENV=prod
ARG TRUSTED_HOSTS=localhost
ARG SENTRY_DSN=<SENTRY_DSN>
ARG BLACKFIRE_PROFILE_ON=false
# prevent the reinstallation of vendors at every changes in the source code
COPY composer.json composer.lock symfony.lock ./
# do not use .env files in production
RUN echo '<?php return [];' > .env.local.php
RUN set -eux; \
composer install --prefer-dist --no-dev --no-autoloader --no-scripts --no-progress --no-suggest; \
composer clear-cache
# copy only specifically what we need
COPY bin bin/
COPY config config/
COPY public public/
COPY src src/
RUN set -eux; \
mkdir -p var/cache var/log; \
composer dump-autoload --classmap-authoritative --no-dev; \
composer run-script --no-dev post-install-cmd; \
chmod +x bin/console; sync
VOLUME /srv/api/var
COPY docker/php/docker-entrypoint.sh /usr/local/bin/docker-entrypoint
RUN chmod +x /usr/local/bin/docker-entrypoint
# Blackfire php probe
RUN version=$(php -r "echo PHP_MAJOR_VERSION.PHP_MINOR_VERSION;") \
&& curl -A "Docker" -o /tmp/blackfire-probe.tar.gz -D - -L -s https://blackfire.io/api/v1/releases/probe/php/alpine/amd64/$version \
&& mkdir -p /tmp/blackfire \
&& tar zxpf /tmp/blackfire-probe.tar.gz -C /tmp/blackfire \
&& mv /tmp/blackfire/blackfire-*.so $(php -r "echo ini_get('extension_dir');")/blackfire.so \
&& printf "extension=blackfire.so\nblackfire.agent_socket=tcp://blackfire:8707\n" > $PHP_INI_DIR/conf.d/blackfire.ini
ENTRYPOINT ["docker-entrypoint"]
CMD ["php-fpm"]
# "nginx" stage
# depends on the "php" stage above
FROM nginx:${NGINX_VERSION}-alpine AS api_platform_nginx
COPY docker/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf
WORKDIR /srv/api
COPY --from=api_platform_php /srv/api/public public/
# "varnish" stage
# does not depend on any of the above stages, but placed here to keep everything in one Dockerfile
FROM cooptilleuls/varnish:${VARNISH_VERSION}-alpine AS api_platform_varnish
COPY docker/varnish/conf/default.vcl /usr/local/etc/varnish/default.vcl
docker-entrypoint:
#!/bin/sh
set -e
# first arg is `-f` or `--some-option`
if [ "${1#-}" != "$1" ]; then
set -- php-fpm "$#"
fi
if [ "$1" = 'php-fpm' ] || [ "$1" = 'php' ] || [ "$1" = 'bin/console' ]; then
PHP_INI_RECOMMENDED="$PHP_INI_DIR/php.ini-production"
if [ "$APP_ENV" != 'prod' ]; then
PHP_INI_RECOMMENDED="$PHP_INI_DIR/php.ini-development"
fi
ln -sf "$PHP_INI_RECOMMENDED" "$PHP_INI_DIR/php.ini"
mkdir -p var/cache var/log
setfacl -R -m u:www-data:rwX -m u:"$(whoami)":rwX var
setfacl -dR -m u:www-data:rwX -m u:"$(whoami)":rwX var
if [ "$APP_ENV" != 'prod' ]; then
composer install --prefer-dist --no-progress --no-suggest --no-interaction
fi
echo "Waiting for db to be ready..."
until bin/console doctrine:query:sql "SELECT 1" > /dev/null 2>&1; do
sleep 1
done
# if [ "$APP_ENV" != 'prod' ]; then
# bin/console doctrine:schema:update --force --no-interaction
# fi
fi
crond -L /srv/api/logs/crond.log -b
exec docker-php-entrypoint "$#"
Commands in cause (in docker-entrypoint.sh):
mkdir -p var/cache var/log
setfacl -R -m u:www-data:rwX -m u:"$(whoami)":rwX var
setfacl -dR -m u:www-data:rwX -m u:"$(whoami)":rwX var
Errors (durring php service up):
setfacl: var/log: Not supported
setfacl: var/log/dev.log: Not supported
Search line:
A new feature of docker-desktop is "New file sharing implementation" that replace (a kind of file sharing system) Samba by FUSE. It's made for developpers like us to improve performances when running symfony or react app through docker.
docker-desktop 2.2 release note here
a docker blog post about FUSE here
Do anyone has a same probleme and maybe a solution ?

Combining php:7.2-alpine with nginx in ond Dockerfile

I have a need to combine the php:7.2 alpine with nginx in one dockerfile( in one docker image ) for production deployment of laravel app.
So I tried my way and I can only add nginx package. I can't find any nginx conf file in my image. I found many someone's images in docker hub. I tried a lot with this images and not working well.
Here is my docker file.
FROM php:7.2-alpine
RUN apk upgrade --update -q \
&& apk --no-cache -q add openssl zip unzip git mysql-client vim coreutils freetype-dev libpng-dev libjpeg-turbo-dev freetype libpng libjpeg-turbo libltdl libmcrypt-dev \
&& docker-php-ext-configure gd \
--with-gd \
--with-freetype-dir=/usr/include/ \
--with-png-dir=/usr/include/ \
--with-jpeg-dir=/usr/include/ && \
NPROC=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || 1) \
&& docker-php-ext-install -j$(nproc) gd pdo pdo_mysql opcache zip calendar \
&& apk del --no-cache -q freetype-dev libpng-dev libjpeg-turbo-dev
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN apk --update add \
supervisor
RUN apk add --update nginx && rm -rf /var/cache/apk/*
RUN mkdir -p /tmp/nginx/client-body
COPY nginx/nginx.conf /etc/nginx/nginx.conf
COPY nginx/default.conf /etc/nginx/conf.d/default.conf
#COPY website /usr/share/nginx/html
WORKDIR /var/www
COPY ./workspace-api /var/www
COPY ./workspace-api/supervisord.conf /etc/supervisord.conf
ADD ./workspace-api/root /etc/crontabs/
ADD ./workspace-api/php.ini /usr/local/etc/php
RUN composer install
RUN chmod -R 755 /var/www
RUN chmod +x /var/www/supervisor.sh
RUN /var/www/supervisor.sh
CMD ["nginx", "-g", "daemon off;"]
PS: I have docker-compose file for multi container app. But in this case, I only need to build all in one image for laravel.

Access my dockerized Laravel app in local

I am trying to dockerize a PHP / Laravel / VueJS app.
Here is the Dockerfile
FROM php:7.2-fpm
LABEL maintainer="contact#kendozone.com"
LABEL version="1.0.0"
LABEL description="Kendozone is a online tournament webapp coded with PHP / Laravel"
ENV node_version 10.8.0
ENV npm_version 6.4.1
ENV NVM_DIR /.nvm
ENV APP_DIR="/var/www"
ENV APP_PORT="80"
ENV DOCKER_FOLDER="docker/local"
RUN echo "deb http://ftp.de.debian.org/debian stretch main " >> /etc/apt/sources.list \
&& apt-get update -y
RUN apt-get install -y openssl zip unzip git gcc make automake \
libfreetype6-dev \
libjpeg62-turbo-dev \
libmcrypt-dev \
libpng-dev \
libmagickwand-dev vim --no-install-recommends
RUN apt-get purge --auto-remove -y g++ \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install pdo pdo_mysql mbstring zip -j$(nproc) iconv -j$(nproc) gd
WORKDIR $APP_DIR
COPY . $APP_DIR
RUN ls $APP_DIR \
&& touch $APP_DIR/database/sqlite.db \
&& mv $DOCKER_FOLDER/.env.local .env \
&& chown -R www-data:www-data $APP_DIR
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer \
&& composer install --no-interaction
RUN mkdir -p $NVM_DIR && chown -R www-data:www-data $NVM_DIR \
&& curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash \
&& [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" \
&& nvm install ${node_version}
ENV NODE_PATH $NVM_DIR/v$node_version/lib/node_modules
ENV PATH $NVM_DIR/versions/node/v$node_version/bin:$PATH
RUN npm install --save-exact imagemin-pngquant#5.0.* \
&& npm install \
&& npm run production \
&& php artisan key:generate \
&& php artisan migrate --seed
EXPOSE $APP_PORT
CMD php artisan serve --host=0.0.0.0 --port=$APP_PORT
the last line is supposed to run local server
Then I build it with :
docker build . -t xoco/kendozone:local-1.0.3
Then I run it with:
docker run -p 80:80 xoco/kendozone:local-1.0.3 -d bash
I can see on terminal the output:
[25-Oct-2018 19:56:40] NOTICE: fpm is running, pid 1
[25-Oct-2018 19:56:40] NOTICE: ready to handle connections
EDIT:
➜ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
fee456200b85 xoco/kendozone:local-1.0.3 "docker-php-entrypoi…" 2 hours ago Up 2 hours 9000/tcp, 0.0.0.0:8080->80/tcp youthful_keldysh
Which seems to mean that everything is ok
But I can't reach my app on 127.0.0.1
What am I missing
You have to add host configuration file while using docker and add an entry for it inside /etc/hosts and try again.
I solved it with this command:
docker run -p 80:80 xoco/kendozone:local-1.0.3
Just remove -d bash at the end, and it should be OK

Build symfony docker container without DB

I have an symfony application, and i want to create docker container, that contains all needed files. The purpose is to spin up/down containers for scaling, without any other deploying processes. Just with given DB connection.
Building means, pretty much just git clone and running composer install, but some of symfony's post install scripts fail without configured DB.
Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache
Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::installAssets
Can i not run these scripts when i'm building container? Or what the proper way to do symfony deployment?
Using Symfony 3.2, Doctrine2, PHP 7.1
The proper way to build a container without running the db script is by not running there scripts in the build,
Here is the one we use in production for api-platform:
FROM php:7.1-fpm-alpine
RUN apk add --no-cache --virtual .persistent-deps \
git \
icu-libs \
zlib \
postgresql-client
ENV APCU_VERSION 5.1.8
RUN set -xe \
&& apk add --no-cache --virtual .build-deps \
$PHPIZE_DEPS \
icu-dev \
zlib-dev \
postgresql-dev \
sqlite-dev \
pcre-dev \
&& docker-php-ext-install \
intl \
mbstring \
pdo_mysql \
pdo_pgsql \
pdo \
pgsql \
zip \
pdo_sqlite \
&& pecl install \
apcu-${APCU_VERSION} \
&& docker-php-ext-enable --ini-name 20-apcu.ini apcu \
&& docker-php-ext-enable --ini-name 05-opcache.ini opcache \
&& apk del .build-deps
COPY docker/php/php.ini /usr/local/etc/php/php.ini
COPY docker/php/install-composer.sh /usr/local/bin/docker-app-install-composer
RUN chmod +x /usr/local/bin/docker-app-install-composer
RUN set -xe \
&& apk add --no-cache --virtual .fetch-deps \
openssl \
&& docker-app-install-composer \
&& mv composer.phar /usr/local/bin/composer \
&& apk del .fetch-deps
ARG SYMFONY_ENV=dev
ENV SYMFONY_ENV=dev
RUN if [ "$SYMFONY_ENV" -ne "dev" ]; then \
sed -i '1 a xdebug.remote_enable=1' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini && \
sed -i '1 a xdebug.remote_handler=dbgp' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini && \
sed -i '1 a xdebug.remote_autostart=0' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini && \
sed -i '1 a xdebug.remote_connect_back=1 ' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini && \
sed -i '1 a xdebug.remote_port=9001' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini && \
sed -i '1 a xdebug.remote_log=/var/log/xdebug_remote.log' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini && \
pecl install \
xdebug \
&& docker-php-ext-enable xdebug; \
fi;
# https://getcomposer.org/doc/03-cli.md#composer-allow-superuser
ENV COMPOSER_ALLOW_SUPERUSER 1
WORKDIR /srv/quotatis
COPY composer.json ./
COPY composer.lock ./
RUN mkdir -p \
var/cache \
var/logs \
var/sessions \
&& composer global require "hirak/prestissimo:^0.3" --prefer-dist --no-progress --no-suggest -o -a \
&& composer install --prefer-dist --no-dev --no-autoloader --no-scripts --no-progress --no-suggest \
&& composer clear-cache \
# Permissions hack because setfacl does not work on Mac and Windows
&& chown -R www-data var
COPY app app/
COPY bin bin/
COPY src src/
COPY web web/
COPY etc etc/
RUN composer dump-autoload --optimize --classmap-authoritative --no-dev
COPY docker/php/start.sh /usr/local/bin/docker-app-start
RUN chmod +x /usr/local/bin/docker-app-start
CMD ["docker-app-start"]
You could see the whole stack (nginx + fpm + varnish on github)
The line that you need in here is this one
composer install --prefer-dist --no-dev --no-autoloader --no-scripts --no-progress --no-suggest

Categories