Reputation: 249
I'm running a php:7.0-apache Docker image, but I have no permissions to write to /var/www/html
. How is it possible to grant write rights to this user?
Dockerfile:
FROM php:7.0-apache
# PHP Extensions
RUN docker-php-ext-install pdo_mysql
# Composer
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
RUN php composer-setup.php
RUN php -r "unlink('composer-setup.php');"
RUN mv composer.phar /usr/local/bin/composer
ADD vhost-default.conf /etc/apache2/sites-enabled/000-default.conf
# Open Ports
EXPOSE 80
EXPOSE 443
Host Conf
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/html >
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Upvotes: 3
Views: 14401
Reputation: 322
Sergiu's answer is not working, because your volume is bound after chown
.
What you should do is that you should run chown
after bound to your volume and before start the Apache.
To do that, I add chown
command in the apache2-foreground
script.
RUN sed -i 's/^exec /chown www-data:www-data \/var\/www\/html/\n\nexec /' /usr/local/bin/apache2-foreground
So when you start your container, it will change the permission to www-data.
PS: Your container's user should be in root
or a user who can execute chown
.
Upvotes: 0
Reputation: 3195
To resolve this you will need to add an extra line in your Dockerfile like:
RUN chown www-data:www-data /var/www/html/
Upvotes: 14