Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Using mounted volumes (folders/files) in docker makes it a lot easier to pass data between the host and the container environment.  Any changes in the host environment to a folder and all its contents, or a file are immediately reflected in the container environment.  Conversely any changes in the container environment to a folder and all its contents, or a file are immediately reflected in the host environment.  To test this will run two instances of tomcat, one mounting a file and other mounting a directory that a file exists within, the commands are (we are assuming that you have previously executed the following commands - docker pull tomcat, followed by docker tag tomcat:latest tomcat-server)

Mount a file

docker run -p 8083:8080 -dit --name ti_1 -v //c/Users/Selvyn/demo/vm_share/html1/index.html:/usr/local/tomcat/webapps/html/index.html tomcat-server

Mount a folder

docker run -p 8083:8080 -dit --name ti_2 -v //c/Users/Selvyn/demo/vm_share/html1:/usr/local/tomcat/webapps/html tomcat-server

The docker run -v will mount a volume, but on Windows it is defaulted to C:\Users\<user home>.  On windows when you type docker run -v <host path>:<container path> the container gets a new mounted location <container path> that is mapped to <host path>.  If you specify the same <host path> in another docker run for the same or different image, the new container will share the same directories and files as all other containers that reference <host path>.  In actual fact on Windows <host path> is a volume within the docker-machine not within the Windows host itself; this is an anomaly because in Linux it would be a path within the Linux host environment. 

...