Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony and Docker - Cache and Log dirs permissions

I am trying to setup a Symfony project using docker but it always return errors related to permissions in "cache" directory.

I have tried everything and I can't seem to find a solution. The problem is somehow the cache folder is always created with "root" owner even with my server and php-fpm user set as www-data. Maybe because of the php-cli user?

I have tried: - setfacl : Don't work with docker - chown / chmod to www-data: also didn't work. it might changes the owner correctly in the begining but them gives an error in other place.

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

My app Dockerfile:

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"]

Nginx Dockerfile

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 am out of ideas. Any suggestions? Thank you.

like image 701
brpaz Avatar asked Nov 20 '22 16:11

brpaz


1 Answers

I have an apache 2.2 setup with docker and at the end of the Dockerfile I have the following command:

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

and this in the fix_symfony_cache_and_logs_permissions script:

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

It seems that your problem could be related to the fact that your php-fpm process is the one who should run with the right permissions.

EDIT: I just found out about this https://github.com/drgomesp/symfony-docker which I think would help you set it up correctly

like image 89
xocasdashdash Avatar answered Dec 04 '22 02:12

xocasdashdash