I am attempting to create a development environment composed of a php:5.6-apache image, a mysql image, and a volume mount containing the website that will be located in /var/www/html/. The volume mount has has October CMS on it.
I need the docker user to have permissions over the volume mount, but I do not want it to be the owner of that volume, so i can easily modify it outside of the container, and see my modifications immediately.
My docker file is as follows:
FROM php:5.6-apache
MAINTAINER me <me@internet>
# Install modules
RUN apt-get update
RUN apt-get -f install -y
RUN apt-get install -y wget
RUN apt-get update && apt-get install -y \
libmcrypt-dev \
libfreetype6-dev \
libjpeg62-turbo-dev \
libmcrypt-dev \
libpng12-dev \
php-apc
RUN docker-php-ext-install mbstring mysql mcrypt pdo pdo_mysql zip
RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/
RUN docker-php-ext-install gd
WORKDIR /var/www/html/
VOLUME /var/www/html/
RUN a2enmod rewrite
RUN usermod -a -G www-data root
RUN php5enmod mcrypt && service apache2 restart
My Docker-compose contains environment variables for the MySql database.
When I run it as is, I just get 500 error, but if I change the ownership of the volume to www-data, the site comes up just fine.
I have tried using environment variables to change the Apache user and group to root, but it did not work.
Any suggestions are greatly appreciated.
UPDATE: I was unable to find a solution that fixed the problem in the exact way I am looking for, and in the end implemented something I view as more of a hack. I added the following lines to the dockerfile:
RUN usermod -u 1000 www-data
RUN groupmod -g 1000 www-data
These lines change the user and group inside the docker to match the owner, thus giving it complete access.
Be aware though that there are some cases your system will not recognize you as user 1000 and group 1000. If this does not work, bash into the docker apache container, and check what the volume has as the user id and group id, and then change the lines above accordingly.
After you run
docker-machine start default
you need to ssh into it and run the following for the above to fully work:sudo mkdir --parents /var/www/html
[assuming that /var/www/html is the shared folder in your virtualbox]sudo mount -t vboxsf -o uid=1000,gid=1000 var/www/html /var/www/html
[this is to make sure the uid and gid is 1000 for the next part to work]All the files that you share in a mounted volume need to have the same uid:guid ownership of the user that runs the CMD in your container. I managed to use some workarounds in my daily work, hopefully one of those could work for you:
Hope it helps!