Script Analytics

2015/11/09

Auto-mount Windows folder to Boot2Docker VM

Boot2Docker is a simple VM used to run Docker in Windows.
With Docker-Machine, you are able to run Docker container inside the Boot2Docker VM from your Windows CMD.
And Everything is bundled into Docker Toolbox.


However, It can be annoying to execute shell scripts inside the Boot2Docker VM then retrieve everything on the Windows FS to finally build the Docker image.
In order to simplify my docker workflow and do everything inside the VM, I wanted to have access to my windows workspace from the boot2docker VM.


By default Boot2Docker has a shared folder with your windows user folder. It would be fine if my workspace was located there but it is not the case.
As the VM is handled by VirtualBox, the following CMD will create a virtual box file system linked to my windows workspace :
%VBOX_HOME%\VBoxManage.exe sharedfolder add boot2docker-vm -name c/workspace -hostpath c:\workspace
Then we can start (or restart) the VM and modify the /var/lib/boot2docker/bootlocal.sh file which will be executed at the start of the VM OS. The file belongs to root so we sudo the command :
sudo vi /var/lib/boot2docker/bootlocal.sh
We add the following commands to auto-mount the virtual box fs into boot2docker VM :
# create local mount folder
sudo mkdir -p /c/workspace
# mount virtual box fs
sudo mount -t vboxsf c/workspace /c/workspace
# add symbolic link to home
sudo ln -s /c/workspace /home/docker/workspace
Restart the VM and you will now be able to read/modify your workspace folder from ~/workspace.

No comments:

Post a Comment