kmilo93sd
kmilo93sd

Reputation: 901

how to set permissions to cache and log symfony docker container

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?

Upvotes: 0

Views: 1853

Answers (1)

β.εηοιτ.βε
β.εηοιτ.βε

Reputation: 39194

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

Upvotes: 4

Related Questions