Edit date on volume via Dockerfile

  docker, docker-compose, dockerfile, drupal

I do want to make a custom Drupal docker-image.

In fact I want to use the standard "drupal" docker-image and add some further tools to it, as well as putting "/var/www/html/sites" diretory to an external volume. In a 2nd step I’d like to have docker create a new "settings.php" on the volume under "sites/default".

So in my "docker-compose.yml" I put:

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

My Dockerfile consists of:

FROM drupal:9.1-php8.0
...
RUN mkdir /var/www/html/xxx2
RUN mkdir /var/www/html/sites/xxx2
RUN mkdir -p /var/www/html/sites/default/files
RUN curl https://raw.githubusercontent.com/drupal/drupal/9.1.x/sites/default/default.settings.php -o /var/www/html/sites/default/default.settings.php
RUN [ ! -f /var/www/html/sites/default/settings.php ] && cp /var/www/html/sites/default/default.settings.php /var/www/html/sites/default/settings.php
RUN chown www-data:www-data /var/www/html/sites -R
...

I did add those "xxx2" directories for testing only.

Now I do build my image with:

docker container prune && docker-compose build --no-cache &&  docker-compose up --force-recreate

And connect to it like this:

docker exec -it d9docker_drupal_1  /bin/bash

Now what I do see in my container is the following :

/var/www/html/xxx2

What I do not see:

/var/www/html/sites/xxx2
/var/www/html/sites/default

I do suppose this might be normal behavior because the volumes are mounted on after image creation, but what would be the best approch for this use case?

Source: Docker Questions

LEAVE A COMMENT