Docker Community Forums

Share and learn in the Docker community.

Way to keep initial contents in a mounted volume


(Bigpapoo) #1

Hi. I’d like to create and mount a volume while preserving its initial contents.
For instance let’s say I instantiate a new httpd container, which by default contains a /usr/local/apache2/htdocs web directory with some initial/default contents. Now I want to mount a local directory on this htdocs mount point so I’ll be able to add/edit my web site directly from my host machine. If I go straight with a :

docker run -v some_local_path:/usr/local/apache2/htdocs httpd

I endup with an empty web site as the initial contents is hidden by the mount.
To preserve the contents I do this :

docker run --rm -v some_local_path:/web httpd cp -a /usr/local/apache2/htdocs /web
docker run -v some_local_path:/usr/local/apache2/htdocs httpd

I’m wondering whether I’m doing it right or if there is another way to perform this directly without this trick ?