Dockerfile "RUN chmod" not taking effect

Maurício Mendonça picture Maurício Mendonça · May 8, 2019 · Viewed 22.2k times · Source

Everything else takes effect but permissions are not changing, am I missing something?

FROM joomla:3.9-php7.2-apache

RUN apt-get update \
&& apt-get install -y apt-utils vim curl

COPY ./joomla_html /var/www/html

RUN chmod -R 765 /var/www/html/

RUN chown -R www-data. /var/www/html/
RUN chmod -R 777 /var/www/html/tmp
RUN chmod -R 777 /tmp
RUN chmod -R 777 /var/www/html/modules
RUN chmod -R 777 /var/www/html/components
RUN chmod -R 777 /var/www/html/administrator/logs
RUN chmod -R 777 /var/www/html/images
RUN chmod -R 777 /var/www/html/uploads

COPY ./docker/php.ini /usr/local/etc/php/conf.d/php-extras.ini

EXPOSE 80

This is what I get, every file has permissions to 1000:1000, I need it to be to www-data

Output of ls -la /var/www/html is

total 144
drwxr-xr-x 19 1000 1000 4096 May 8 18:53 .
drwxr-xr-x 1 root root 4096 May 8 02:30 ..
drwxr-xr-x 25 1000 1000 4096 May 8 18:53 components
drwxr-xr-x 6 1000 1000 4096 May 8 18:53 images
drwxr-xr-x 68 1000 1000 4096 May 8 18:53 modules
drwxr-xr-x 2 1000 1000 4096 May 8 18:53 tmp
drwxr-xr-x 2 1000 1000 4096 May 8 18:53 uploads

Answer

Mihai picture Mihai · May 8, 2019

You should set the owner directly when you copy the files:

FROM joomla:3.9-php7.2-apache

RUN apt-get update \
&& apt-get install -y apt-utils vim curl

COPY --chown=www-data:www-data ./joomla_html /var/www/html

RUN chmod -R 765 /var/www/html/

COPY ./docker/php.ini /usr/local/etc/php/conf.d/php-extras.ini

EXPOSE 80