问题
I am learning Docker and trying to understand volumes. Looking at this example of wordpress compose and its dockerfile I don't get which command is responsible for populating wordpress files into /var/www/html.
I do see that there is VOLUME /var/www/html command in the dockerfile to create a mount point.
There is command to download wordpress files and put in /usr/src/wordpress directory.
But what I don't get is how does files get into /var/www/html?
Is it just that mounting to this directory cause all the wordpress files magically stored in this?
Is it somewhere else docker is doing this?
EDIT: These wordpress files are already moved or copied when ran docker-compose up. I'm not asking how can move/mount files into /var/www/html. But question is how this things happened referring to the dockerfile and docker compose file above.
Thanks
回答1:
In this case, the entrypoint is copying the files if they don't already exist. Note in the Dockerfile that the wordpress source is added to /usr/src/wordpress. Then, when the container starts, the entrypoint checks if some files exist and if they don't, it copies the wordpress source into the current directory, which is WORKDIR, which is /var/www/html.
General Docker Volume Stuff
With /var/www/html specified as a VOLUME, the only way to get files into there from the container's perspective is to attach a docker volume with files to that. Think of it as a mountpoint.
You can either attach a local filesystem to that volume:
docker run -v /path/to/local/webroot:/var/www/html wordpress
or you can create a docker volume and use it for a persistent, more docker-esque object:
docker volume create webroot
And then move the files into it with a transient container:
docker run --rm -v /path/to/local/webroot:/var/www/html \
-v webroot:/var/www/html2 \
ubuntu cp -a /var/www/html/ /var/www/html2
at which point you have webroot as a docker volume you can attach to any container.
docker run -v webroot:/var/www/html wordpress
来源:https://stackoverflow.com/questions/46306229/from-where-how-the-files-get-populated-in-var-www-html