1

I am trying to setup an Apache web project locally using Dockerfile and Docker compose on a Mac Yosemite with Boot2docker/Virtualbox. Everything works except for one thing - file permissions on mounted volumes. I need to have some folders writable by PHP and I can't find a way to change permissions in my build.

This is my Dockerfile:

FROM ubuntu:latest

RUN apt-get update
RUN apt-get -y upgrade

# Install apache, PHP, and supplimentary programs. curl and lynx-cur are for debugging the container.
RUN DEBIAN_FRONTEND=noninteractive apt-get -y install apache2 libapache2-mod-php5 php5-mysql php5-gd php-pear php-apc php5-curl curl lynx-cur

# Enable apache mods.
RUN a2enmod php5
RUN a2enmod rewrite

# Update the PHP.ini file, enable <? ?> tags and quieten logging.
RUN sed -i "s/short_open_tag = Off/short_open_tag = On/" /etc/php5/apache2/php.ini
RUN sed -i "s/error_reporting = .*$/error_reporting = E_ERROR | E_WARNING | E_PARSE/" /etc/php5/apache2/php.ini

# Manually set up the apache environment variables
ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV APACHE_LOG_DIR /var/log/apache2
ENV APACHE_LOCK_DIR /var/lock/apache2
ENV APACHE_PID_FILE /var/run/apache2.pid

EXPOSE 80

# Update the default apache site with the config we created.
COPY apache-config.conf /etc/apache2/sites-available/000-default.conf

# By default, simply start apache.
CMD /usr/sbin/apache2ctl -D FOREGROUND

This is /build/docker-compose.yml:

web:
   build: ../.
   ports:
       - 8080:80
   volumes:
       - ../www:/var/www/site
   links:
       - mysql
mysql:
   image: mysql:5.6
   ports:
       - 3306:3306/tcp
   restart: on-failure
   environment:
       - MYSQL_ROOT_PASSWORD=demo
       - MYSQL_DATABASE=demo
       - MYSQL_USER=demo
       - MYSQL_PASSWORD=demo

I need to have some directories in /var/www/site writable. Have tried various alternatives with chmod and chown but can't seem to make anything work within the docker container...

The whole project resides within the /Users folder.

Docker inspect on my web container gives me the following mounts:

"Mounts": [
    {
        "Source": "/Users/[myuser]/Documents/[project]/www",
        "Destination": "/var/www/site",
        "Mode": "rw",
        "RW": true
    },
    {
        "Source": "/mnt/sda1/var/lib/docker/volumes/9018974b47f606c262fc1127a2a9ca6420841ca59a3a064e9adee6a6bfacd70f/_data",
        "Destination": "/var/www",
        "Mode": "rw",
        "RW": true
    },
    {
        "Name": "8105b731c655cdaf53d93c2e78a4a3104d4650b49df5879c2004a2aef3a7d9e0",
        "Source": "/mnt/sda1/var/lib/docker/volumes/8105b731c655cdaf53d93c2e78a4a3104d4650b49df5879c2004a2aef3a7d9e0/_data",
        "Destination": "www",
        "Driver": "local",
        "Mode": "",
        "RW": true
    }

So I guess everything is mounted the way it should be? The permissions I can't seem to get right though.

purpleninja
  • 376
  • 3
  • 11
  • Check this out http://stackoverflow.com/questions/33575351/docker-machine-on-mac-cannot-see-mounted-volumes-on-docker-host-docker-machine/33576208#33576208, already answered at length there :) – Armin Braun Mar 06 '16 at 12:15
  • Thanks, I've already read that text and several others but I still haven't understood how to make a folder within the mounted directory writable. – purpleninja Mar 06 '16 at 13:53
  • 1
    Did you apply the suggestion of running a usermod on your Apache user ? – Armin Braun Mar 06 '16 at 14:17
  • Gah, I don't know how many times I tried that in different ways back and forth :) I think I must have just tried to rebuild without cache and I apparently needed to kill the machine and create a new one. Now it seems to work just running usermod for www-data as it should. Thanks again! – purpleninja Mar 06 '16 at 15:49

0 Answers0