Code Disciples

A blog for all things code

Wed 18 September 2019

Bind Mounting with Docker Toolbox on Windows

Posted by Abhishek Pednekar in Docker   

If you have racked your brains trying to get Docker bind mounting to work on Windows, you certainly are not alone. Documentation for Docker on Windows is not exactly verbose, especially if you are using the Docker Toolbox. In this post, we will look at binding a local Windows folder to a directory in a Docker Container using Docker Toolbox. In the example below, we will create an nginx container with a bind to a local folder in "C:\Users". We will test the bind by copying over files from the local folder to the container.

An important thing to note on Windows is to use //<drive letter>/ to reference our local drive in the docker container run command. For instance, to reference "C:\Users", we will use "//c/users".

Next, we will add a shared folder on our virtual machine (VM). In this example, Oracle VirtualBox provides the VM to run Docker Toolbox. We can add a shared folder in the Settings of our VM.


vm1


To add a shared folder, we will select the Shared Folders option. We will then need to specify the desired folder on our computer and give it an appropriate name. This name will be used in the docker container run command. So in the example below, by including "//c/Docker" in our command, we are simply referring to "C:\users\abhi_\Docker". Be sure to select the Auto Mount and Make Permanent options. For these settings to take effect, the VM will need to be restarted. To reboot, right-click on the VM and select Reset.


vm2


The local "Docker" folder has two files. These will get copied over to the directory (in our container) which will be bound to the local folder using the -v or --volume options.


vm3


Finally, we will create our nginx container. The -v //c/Docker:/usr/share/nginx/html in the command, binds "C:\users\abhi_\Docker" to "/usr/share/nginx/html" on the container.

docker container run -d --name nginx -p 80:80 -v //c/Docker:/usr/share/nginx/html nginx

To verify whether the bind mounting worked, we will run bash on the container and look for the files in "/usr/share/nginx/html".


vm4


Share



Comments