0

I am trying to create a simple local docker setup with Grav CMS (getgrav.org).

I have successfully gotten the docker container to spin up and server me the proper files, however when I try to create a mounted volume for the "user" directory of the CMS things seem to break.

Here is my Dockerfile:

FROM php:7-apache

RUN set -xe \
    && mkdir -p /usr/src/grav/.unpacked \
    && apt-get update && apt-get install -y libpng12-0 git unzip libpng12-dev --no-install-recommends \
    && rm -rf /var/lib/apt/lists/* \
    && docker-php-ext-install gd zip \
    && a2enmod rewrite

ENV GRAV_URL "https://getgrav.org/download/core/grav/1.3.3"

RUN set -xe \
    && curl -fSL -o /usr/src/grav/grav.zip "$GRAV_URL" \
    && unzip /usr/src/grav/grav.zip -d /usr/src/grav/.unpacked \
    && rm /usr/src/grav/grav.zip \
    && mv /usr/src/grav/.unpacked/*/* /usr/src/grav \
    && mv /usr/src/grav/.unpacked/*/.[!.]* /usr/src/grav \
    && rm -rf /usr/src/grav/.unpacked \
    && chown -R www-data:www-data /usr/src/grav \
    && cd /usr/src/grav \
        && bin/gpm selfupgrade -y \
        && bin/gpm install -y admin git-sync

VOLUME /var/www/html

COPY ./docker-entrypoint.sh /entrypoint.sh

ENTRYPOINT [ "/bin/sh", "/entrypoint.sh" ]
CMD [ "apache2-foreground" ]

My docker-compose.yml file:

version: '2'
services:

  grav:
    image: grav
    container_name: gravdocker
    ports:
      - "8080:80"
    environment:
      VIRTUAL_HOST: gravlocal.docker

and my docker-entrypoint.sh:

#!/bin/sh
set -e

if [ -z "$(ls -A /var/www/html)"]; then
    cp -a /usr/src/grav/. /var/www/html/
    chown -R www-data:www-data /var/www/html
        if [ "$GRAV_REVERSE_PROXY" = "true" ]; then
        sed -i "s/reverse_proxy_setup:\sfalse/reverse_proxy_setup: true/g" \
        system/config/system.yaml
    fi
fi

exec "$@"

With this setup everything is okay. When I add

volumes:
  - ./user:/var/www/html/user

to the docker-compose file, I get a forbidden error in the browser. When I try to specify another volume in the dockerfile for the user directory it also gives me a forbidden warning in the browser.

My goal is to have the CMS running in docker and listening for a user directory locally so I can do theme development and have a local version of the files.

artemartemov
  • 163
  • 1
  • 8
  • I have tried adding volumes: - ./user:/var/www/html/user and that always overwrites the entire directory of var/www/html and not just user. – artemartemov Sep 23 '17 at 20:21
  • After running docker-compose up, try running `docker-compose exec grav chown -R www-data:www-data /var/www/html` – Tarun Lalwani Sep 24 '17 at 04:41
  • @TarunLalwani I actually somewhat figured out what the issue is. In my docker-compose.yml when I add the lines: `volumes: - ./user:/var/www/html/user` it actually replaces the whole /html/ directory with an empty user directory instead of just appending the user directory. Do I need to add something to docker-entrypoint.sh to possible avoid that? – artemartemov Sep 25 '17 at 15:11
  • Actually if you map a child directory then parent should not be impacted. Make sure without mapping `/var/www/html` is not empty. If it is not empty and it is showing empty then it is a bug in docker, you should report it – Tarun Lalwani Sep 25 '17 at 16:04
  • So currently, if I add the volumes line to the docker-compose file - the directory is empty sans the /user/ directory that I am adding as a volume removing that line from docker-compose and everything is working as intended (but the directory is obviously served only from the container) @TarunLalwani you are thinking this is a bug from docker? – artemartemov Sep 25 '17 at 17:15
  • This looks like a bug, but to confirm what is the output of `tree -L2 /var/www/html` with and without the volume mapping? please add to your question the outputs – Tarun Lalwani Sep 25 '17 at 20:32

0 Answers0