I am having these two dockerfiles which in both I am adding the command RUN chown -R www-data:www-data /var/www/html
to change the ownership to www-data user. The containers seems to build successfully with no errors, however when I ssh for example into the running php container and run ls -la
on the workingdir I can still see all files and folders are owned by root. If I do ls -la
outside of the running container on my local env I can see them owned by my username and staff.
// Apache
FROM httpd:alpine
COPY ./docker/apache/httpd-vhosts.conf /usr/local/apache2/conf/extra/httpd-vhosts.conf
WORKDIR /var/www/html/
COPY ./public /var/www/html/public
RUN chown -R www-data:www-data /var/www/html
EXPOSE 80
CMD ["httpd", "-D", "FOREGROUND"]
-----
// PHP
FROM php:8.1-fpm-alpine
# Install any additional dependencies like pdo, xdebug etc
RUN apk add --no-cache --update linux-headers \
${PHPIZE_DEPS} \
openssl-dev \
&& docker-php-ext-install pdo pdo_mysql
# Set up the php configuration in the container
COPY ./docker/php/php.ini /usr/local/etc/php/php.ini
COPY ./docker/php/conf.d/*.ini /usr/local/etc/php/conf.d/
# Copy the codebase in the working dir of the container
WORKDIR /var/www/html
COPY . /var/www/html
RUN chown -R www-data:www-data /var/www/html
EXPOSE 9000
CMD ["php-fpm", "-y", "/usr/local/etc/php-fpm.conf", "-R"]
What do I need to do to make sure the files & folders are owned by www-data user within the containers?