Mounting /etc/apache2 directory from system to container

I’m new to docker and I’m trying to create a new php (apache) image. I want to externalize the /etc/apache2, /var/www/html, and /usr/local/etc/php directories so they don’t live within the container, but live on my main system which docker is running on.

Here is my simple Dockerfile that I used:

FROM php:7.0-apache
VOLUME ["/var/www/html", “/etc/apache2”, “/usr/local/etc/php”]

Then when I built that and created a container:

docker create
–name apache
–restart=always
-v /home/user/apache/conf:/etc/apache2
-v /home/user/apache/html:/var/www/html
-v /home/user/apache/php:/usr/local/etc/php
-e TZ=America/New_York
-p 80:80 -p 443:443
apache

When I start the container, the /etc/apache2 configs are all missing… I’m expecting them to get populated within my /home/user/apache/conf directory upon container startup… What am I doing wrong? I’ve run other containers from linuxserver.io where I setup a /config directory similarly and all the config gets auto-populated on it’s own when I start the container. Thanks in advance.

I thought about it more and I think because I’m not targeting Ubuntu and using apt-get to install packages, the configs don’t get populated on container start…

Whatever is in /home/user/apache/conf before you create the container, will be mounted over /etc/apache2 inside the container.

This Dockerfile doesn’t do much (if you create a container without -v options for those directories, Docker will auto-create a volume and copy the preexisting content there, which is probably what you were expecting; but if you give an explicit -v option, which you usually do in practice, the automatic copy doesn’t happen) and I’d just directly run the base image with the relevant -v options.