0

I have a Dockerfile for my Symfony application but the container doesn't have write permissions into the cache and logs directories.

I tried with the Symfony docs for permissions, but it is not working. I already set the container user to root, but the problem is the same.

Here is my Dockerfile:

FROM trafex/alpine-nginx-php7:ba1dd422

RUN apk --update add git php7-sockets php7-bcmath php7-pdo_mysql php7-pdo && rm /var/cache/apk/* \
    && curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

COPY ./docker/nginx/nginx.conf /etc/nginx/nginx.conf

COPY . /var/www/html

RUN composer install \
     --ignore-platform-reqs \
        --no-interaction \
        --no-plugins \
        --no-scripts \
        --prefer-dist

EXPOSE 8080

How can I set the correct permissions to run it?

β.εηοιτ.βε
  • 33,893
  • 13
  • 69
  • 83
kmilo93sd
  • 791
  • 1
  • 15
  • 35

1 Answers1

4

From the Dockerfile of the docker image it seems like the user running both NGINX and PHP-FPM is nobody.

So you should be able to make it all work giving this user the rights on those files

FROM trafex/alpine-nginx-php7:ba1dd422

RUN apk --update add git php7-sockets php7-bcmath php7-pdo_mysql php7-pdo && rm /var/cache/apk/* \
    && curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

COPY ./docker/nginx/nginx.conf /etc/nginx/nginx.conf

COPY . /var/www/html
RUN chown -R nobody:nobody /var/www/html

RUN composer install \
     --ignore-platform-reqs \
        --no-interaction \
        --no-plugins \
        --no-scripts \
        --prefer-dist

EXPOSE 8080

But better yet, you should use the same syntax as they use in the original image

FROM trafex/alpine-nginx-php7:ba1dd422

RUN apk --update add git php7-sockets php7-bcmath php7-pdo_mysql php7-pdo && rm /var/cache/apk/* \
    && curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

COPY ./docker/nginx/nginx.conf /etc/nginx/nginx.conf

COPY --chown=nobody . /var/www/html

RUN composer install \
     --ignore-platform-reqs \
        --no-interaction \
        --no-plugins \
        --no-scripts \
        --prefer-dist

EXPOSE 8080
β.εηοιτ.βε
  • 33,893
  • 13
  • 69
  • 83