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.
// ApacheFROM httpd:alpineCOPY ./docker/apache/httpd-vhosts.conf /usr/local/apache2/conf/extra/httpd-vhosts.confWORKDIR /var/www/html/COPY ./public /var/www/html/publicRUN chown -R www-data:www-data /var/www/htmlEXPOSE 80CMD ["httpd", "-D", "FOREGROUND"]-----// PHPFROM php:8.1-fpm-alpine# Install any additional dependencies like pdo, xdebug etcRUN 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 containerCOPY ./docker/php/php.ini /usr/local/etc/php/php.iniCOPY ./docker/php/conf.d/*.ini /usr/local/etc/php/conf.d/# Copy the codebase in the working dir of the containerWORKDIR /var/www/htmlCOPY . /var/www/htmlRUN chown -R www-data:www-data /var/www/htmlEXPOSE 9000CMD ["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?