3

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

cjmling
  • 6,896
  • 10
  • 43
  • 79

1 Answers1

2

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
kojiro
  • 74,557
  • 19
  • 143
  • 201
  • If i understand correctly , you are telling me how I can and move or mount files into `/var/www/html` right ? If i'm right then may be you misunderstood me. Wordpress files are already moved/copied into `/var/www/html` when i did `docker-compose up`. So my question is how that happened? :S And I don't see any files attached command to that volume in `dockerfile` or `docker-compose.yml` – cjmling Sep 19 '17 at 17:32
  • Right you are. Edited. – kojiro Sep 19 '17 at 17:38