If you are using Docker Toolbox (boot2docker) and want to make files available to your containers, or have the containers write data to permanent storage on your Windows system outside of the container, you need to first share a folder from your Windows system with the Docker host virtual machine.
This is a guide to create a shared folder in Virtual Box and then mount that folder in the virtual machine.
First, make sure the docker host VM is stopped:
docker-machine stop
Create the VirtualBox shared folder for the virtual machine:
cd 'c:\Program Files\Oracle\VirtualBox\'
.\VBoxManage.exe sharedfolder add "<your-vm-name>" --name "<some_name>" --hostpath "C:\Some\Directory"
For example:
\VBoxManage.exe sharedfolder add "default" --name "foo" --hostpath "C:\Foo"
Start the Docker host VM and ssh into it:
docker-machine start
docker-machine ssh
The folder where you want to mount the shared folder must exist before mounting:
mkdir /home/docker/foo
Mount the shared folder:
sudo mount -t vboxsf -o uid=1000,gid=50 your-shared-folder-name /home/docker/foo
Make sure everything worked by checking that the folder has the expected contents:
ls /home/docker/foo
If everything worked you have to make this permanent by adding the mount command to the docker profile:
vi /mnt/sda1/var/lib/boot2docker/profile
Add the mkdir
and mount
commands from above (no sudo required though) to the end of the profile file.
Make sure that the profile changes worked by restarting the docker machine and checking the folder contents:
docker-machine stop
docker-machine start
ls /home/docker/foo
Note: The docker-machine commands above assumes that the currently active docker machine is the one to which you want to add the shared folder, otherwise you need to specify the machine name when using the docker-machine commands.