While this technique works for both Windows and OSX, most Windows developers I know don’t keep their source code in the
Users folder on the system drive. Historically there have been too many problems:
- The path used to start with
C:\Documents and Settings\[USER_NAME]\
msbuildblows up when your path is longer than 256 characters
- There’s no convenient
~/command-line shortcut when typing the path on the command-line.
However, that’s the only default path you get when you create a
boot2docker image for VirtualBox.
In my last post I showed how to mount a VirtualBox shared folder but as soon as you restart (that never happens on a Windows box) you’ve lost it and have to create the mount all over again.
Mount a shared folder
Just to review, so you don’t have to read the last post:
Create a shared folder in VirtualBox:
sshinto your Guest OS (Docker VM):
$ docker-machine ssh defualt
Create a new folder for your mount:
$ sudo mkdir -p /mnt/src
-pis just in case
/mntdoesn’t already exist.
Add your new mount:
$ sudo mount -t vboxsf -o defaults,uid=`id -u docker`,gid=`id -g docker` src /mnt/src
id -u dockerand
id -g dockerwill use the user id and group id respectively. You could just enter
50respectively and you’d be fine. I think the longer version is more clear and safe.
You should now be able to view the contents of your directory within your Docker VM:
$ ls /mnt/src
Make It Permanent
The problem is everything gets erased whenever you restart your VM. What we need is a setup script that won’t be erased and will run on startup. It turns out it’s pretty easy. Create a file named
bootlocal.sh at the following location:
$ sudo touch /mnt/sda1/var/lib/boot2docker/bootlocal.sh
Now add the following to the file (no
mkdir -p /mnt/src mount -t vboxsf -o defaults,uid=`id -u docker`,gid=`id -g docker` src /mnt/src
Make sure you save and close the file. That’s it! If you
ssh session, then restart your VM:
$ docker-machine restart default
Once it’s finished, log back in and verify it’s there:
$ docker-machine ssh default $ ls /mnt/src
You should see the contents of your shared folder.