Docker Toolbox, Windows 7, and Shared Volumes

Docker Toolbox, Windows 7, and Shared Volumes

Docker is a container platform with so much to offer, and I've already published a quick guide on how to set it up in an earlier article. However, if you don't meet the system requirements for the newer versions then you will have to rely on Docker Toolbox, which is described as a legacy desktop solution:

Docker Toolbox is for older Mac and Windows systems that do not meet the requirements of Docker for Mac and Docker for Windows. We recommend updating to the newer applications, if possible.

To operate, Docker Toolbox installs a VirtualBox virtual machine named default, running the boot2docker Linux distribution. Because of this additional layer of virtualisation, additional steps are needed when sharing volumes between the host operating system and a Docker container. For example, a computer lab that I use for teaching runs Windows 7 with restricted student access. I have convinced our IT team to install Docker Toolbox, but my students still need some way of sharing a folder on their student drive (herein referred to as the H:\ drive) with the Docker container.

Preparing VirtualBox to Share Folders

To achieve this, the folder (e.g. H:\work) needs to be shared with the VirtualBox virtual machine named default, before it can be mounted as a volume within a Docker container. There may be other approaches, but here are the steps for our particular set-up:

  1. Open "Docker Quickstart Terminal".
  2. Once Docker is running, type docker-machine stop default.
  3. Open the Command Line from the start menu (search for cmd.exe).
  4. Navigate to the VirtualBox folder using cd C:/Program Files/Oracle/VirtualBox
  5. Type VBoxManage.exe sharedfolder add default --name "h/work" --hostpath "\\?\h:\work" --automount
  6. Type VBoxManage.exe setextradata default VBoxInternal2/SharedFoldersEnableSymlinksCreate/v-root 1
  7. Type VBoxManage.exe setextradata default VBoxInternal2/SharedFoldersEnableSymlinksCreate/h/work 1

The above steps will prepare VirtualBox for sharing H:\work. Now we need to mount the directory inside our docker-machine:

  1. Open "Docker Quickstart Terminal".
  2. Once Docker is running, type docker-machine ssh default
  3. Type sudo mkdir --parents /h/work
  4. Type sudo mount -t vboxsf h/work /h/work/
  5. Type exit

You can now create Docker container instances and share the H:\work folder with them as a mounted volume. Let's demonstrate this with jupyter/scipy-notebook

Sharing Folders with a Docker Container

To create a Docker container from the jupyter/scipy-notebook image, type the following command and wait for it to complete execution: docker run --name="scipy" --user root -v /h/work:/home/jovyan -d -e GRANT_SUDO=yes -p 8888:8888 jupyter/scipy-notebook start-notebook.sh --NotebookApp.token=''

This may take some time, as it will need to download and extract the image. Once it's finished, you should be able to access the Jupyter notebook using 127.0.0.1:8888. I hope this helps you get up and running with Docker Toolbox and shared folders. Of course, the process is typically easier when using the non-legacy Docker solutions.

Comments from the old blog

I've migrated this post from my old blog and set up a redirect, just in case it's still useful to someone (like those in the comments below).

Comments

Stay up to date

Get notified when I publish something new, and unsubscribe at any time.