Docker Community Forums

Share and learn in the Docker community.

Docker volume on existing image

Hello, first of all I’m newbie in docker.
I’m trie to build an image PHP-Apache-Let’sEncrypt, actually my Dockerfile look like this :
FROM php:7.4.3-apache-buster

VOLUME /etc/apache2
VOLUME /etc/letsencrypt
VOLUME /etc/php/7.4

RUN apt-get -qq update
RUN apt-get -qq install -y python3
# le non install recommends fait failed des install pip par la suite
RUN apt-get -qq install -y python3-pip

RUN pip3 install -q --upgrade setuptools
RUN pip3 install -q cryptography==2.8
RUN pip3 install -q certbot
RUN pip3 install -q certbot-dns-ovh
ENV OVH_ENDPOINT "ovh-eu"
ENV OVH_APP_KEY ""
ENV OVH_APP_SECRET ""
ENV OVH_CON_KEY ""
RUN echo "dns_ovh_endpoint = ${OVH_ENDPOINT}" >> /root/.ovhapi
RUN echo "dns_ovh_application_key = ${OVH_APP_KEY}" >> /root/.ovhapi
RUN echo "dns_ovh_application_secret = ${OVH_APP_SECRET}" >> /root/.ovhapi
RUN echo "dns_ovh_consumer_key = ${OVH_CON_KEY}" >> /root/.ovhapi
RUN mkdir /root/apache2_commandes
COPY ressources /root/apache2_commandes

EXPOSE 80
EXPOSE 443

And when I trie to mount volume before, volume are empty and not filled with default configuration.
Why ?
Because when I see mariadb dockerfile (here), it’s VOLUME which allows you to create the folder with a configuration in it.

Please make yourself aquinted with bind mounts to see the difference between bind mounts and (named) volumes.

Either you will have to use named volumes OR if you want to support bind-mounts you will have to add an entrypoint script that copies the required files from a source folder into the volume target.