A journey into the web...

Docker volume issue

It happens, rarely, you have correctly configured your container, everything runs smoothly, no error logs... But your volume hasn't been mounted. Even docker inpect doesn't tell you much about your issue. It could be because of how your hard disk(s) is/are setup : your system is on the partition c: while the volume you want to mount is on another partition.

Here you will read about a workaround to setup docker with another partition. Since Docker has been updated since, please be aware that windows 7, docker 1.11.1 and virtual box 5.0.20 are required, otherwise I can't insure you the following workaround will solve your volume mounting issue.

About the issue

When you intall Docker with Virtual Box (VB), by default Docker installation will share your system partition — c: in most case — with docker's virtual machine. The shared folder allows docker's virtual machine boot2docker to mount volumes from your system partition.

c:\Users mounted in docker's virtual machine

A problem arises when you try to mount anything that is not in your system partition : the volume is missing from docker's virtual machine because it only shares with your system partition — actually it shares c:\Users folder by default.

Workaround

Configure Virtual Box to share your volume

The first step is to share your project folder you want to mount with a container. To do this, you have to open VB. Lets assume we want to mount e:\Users\me\project\awe-stuff. Now that VB is opened, you can see docker's machine which is by default called... Well... default. Right click on the machine, go to settings, then in the left nav bar find Shared Folders. This is here where you have to tell the machine what is your project path. On the right you can see a folder icon with a green plus sign, click on this icon. It opens the following dialog.

  • Folder path : your project path,
  • Folder name : I recommend to put your project's name,
  • Auto-mount : select,
  • Make Permanent: select

The folder is now shared with docker's machine, it must know where and how to mount this folder.

Configure boot2docker

Open docker's terminal or your favorite terminal, docker-machine should be installed. Follow the instructions below.

docker-machine ssh default #default is the docker's machine name
vi /var/lib/boot2docker/bootlocal.sh
# It opens an empty file, insert the two lines below
mkdir /var/awe-stuff
mount -t vboxsf awe-stuff /var/awe-stuff
# save and quit the editor
exit
docker-machine restart default

The file bootlocal.sh is a script that will mount the shared folder you setup via VB — awe-stuff in my case.

That's it

Everytime you will run docker, it'll mount the shared folder which points to your project folder. Now, to mount this to a container, when you setup the volume configuration you have to specify /var/awe-stuff or /var/<project name you shared and mounted in docker's machine>.

I hope this helps. Please, if you see anything wrong or ambigous, your feedbacks are welcomed.

If you liked it, share it!