Symfony and Docker Permissions - Cache and Log dirs

I am trying to set up a Symfony project using docker, but it always returns permissions related to permissions in the cache directory.

I tried everything and I can not find a solution. The problem is that the cache folder is always created with the owner "root", even if my server and user php-fpm are configured as www-data. Maybe due to php-cli user?

I tried: - setfacl: not working with docker - chown / chmod for www data: also not working. this may change the owner correctly at the beginning, but they give an error elsewhere.

docker-compose.yml

app:
  build: .
  command: "tail -f /dev/null" # keep the application container running
  links:
      - mysql
  volumes:
    - .:/var/www

nginx:
  build: docker/nginx/
  ports:
    - 8090:80
  links:
    - php-fpm
  volumes_from:
    - app

php-fpm:
  build: docker/fpm
  ports:
    - 9000:9000
  volumes_from:
    - app

mysql:
  image: mysql:5.7
  volumes:
     - ./docker/data/mysql:/var/lib/mysql

Dockerfile of my application:

FROM php:5.6-cli

ENV DEBIAN_FRONTEND noninteractive

RUN apt-get update && apt-get install -y \
    git \
    vim \
    curl \
    php5-json \
    php5-intl \
    php5-mcrypt \
    php5-mysql \
    php5-apcu \
    php5-gd

ADD /docker/fpm/php.ini /usr/local/etc/php/

# install composer.
RUN curl -sS https://getcomposer.org/installer | php
RUN mv composer.phar /usr/local/bin/composer

RUN usermod -u 1000 www-data

ADD . /var/www

WORKDIR /var/www

Php-fpm dockerfile

FROM php:5.6-fpm

ENV DEBIAN_FRONTEND noninteractive

RUN apt-get update && apt-get install -y \
    php5-json \
    php5-intl \
    php5-mcrypt \
    php5-mysql \
    php5-apcu \
    php5-gd

RUN apt-get install -y php5-xdebug
ADD xdebug.ini /usr/local/etc/php/conf.d/
ADD php.ini /usr/local/etc/php/

EXPOSE 9000

WORKDIR /var/www   
CMD ["php-fpm"]

Docker nginx file

FROM nginx:latest


ENV DEBIAN_FRONTEND noninteractive

RUN apt-get update && apt-get install -y git vim
ADD nginx.conf /etc/nginx/
ADD symfony.conf /etc/nginx/sites-available/

RUN mkdir -p /etc/nginx/sites-enabled
RUN ln -s /etc/nginx/sites-available/symfony.conf /etc/nginx/sites-enabled/

RUN usermod -u 1000 www-data

EXPOSE 80
EXPOSE 443

ENTRYPOINT ["nginx"]

I have no ideas. Any suggestions? Thanks.

+5
2

apache 2.2 , Dockerfile :

ENTRYPOINT service apache2 start && sh /opt/fix_symfony_cache_and_logs_permissions.sh

fix_symfony_cache_and_logs_permissions script:

rm -rf /{route_to_app}/app/cache/* /{route_to_app}/app/logs/* tailf /dev/null

, , php-fpm- - , .

EDIT: https://github.com/drgomesp/symfony-docker, , ,

0

. , chown, chmod, setfacl. . . /. !

FROM php:5.6.29-apache

RUN apt-get update \
  && apt-get install -y git libssl-dev zlib1g-dev libicu-dev g++ \
  && docker-php-ext-install intl mbstring zip \
  && a2enmod rewrite
RUN pecl install mongo \
  && echo extension=mongo.so > /usr/local/etc/php/conf.d/mongo.ini \
  && docker-php-ext-enable mongo \
  && pecl install mongodb && \
  docker-php-ext-enable mongodb

COPY apache2.conf /etc/apache2/apache2.conf

COPY . /var/www/html

WORKDIR /var/www/html

RUN rm -rf /var/www/html/var/cache/prod \
    && rm -rf /var/www/html/var/cache/dev

RUN chown -R www-data /var/www
RUN chmod -R 777 /var/www

USER www-data

RUN curl -sS https://getcomposer.org/installer | php

RUN php composer.phar install --no-interaction --optimize-autoloader

USER root

apache2.conf .

User www-data
Group www-data
ErrorLog /proc/self/fd/2

IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf

Listen 80
DocumentRoot /var/www/html/web
<Directory /var/www/html/web>
    AllowOverride None
    Order Allow,Deny
    Allow from All

    <IfModule mod_rewrite.c>
        Options -MultiViews
        RewriteEngine On
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^(.*)$ app.php [QSA,L]
    </IfModule>
</Directory>

AccessFileName .htaccess
<FilesMatch "^\.ht">
    Require all denied
</FilesMatch>

<FilesMatch \.php$>
    SetHandler application/x-httpd-php
</FilesMatch>

DirectoryIndex disabled
DirectoryIndex app.php
-1

Source: https://habr.com/ru/post/1626778/


All Articles