Skip to content

Instantly share code, notes, and snippets.

@zaenk
Last active April 26, 2017 07:11
Show Gist options
  • Save zaenk/97cb663738ca8e0225da25a28f2feb75 to your computer and use it in GitHub Desktop.
Save zaenk/97cb663738ca8e0225da25a28f2feb75 to your computer and use it in GitHub Desktop.
Docker volumes on Windows

Docker volumes on Windows

Docker for Windows needs a shared drive in order to use it as a root for shared volumes for containers. I don't feel like sharing my whole C: drive, or a creating a new partition on one of my existing disk solely for this purpose.

subst

First I tried to fix this with subst DOS command, it saved me once while I wanted to delete a really deep node_modules directory, but I wanted a solution where I can move around this mounted drive on the host.

Mount a VHD

My solution is to create a VHD, and mount it as a drive, and share it. Here are the steps to set it up:

  • Open Disk Management tool (Win+R diskmgmt.msc or Start menu: Create and format hard disk partiions)
  • Actions > Create VHD
  • Initialize new disc
  • Create partition, assign drive letter (like S)
  • Go to This PC > right click S: > Properties > Sharing > Advanced sharing
  • Check Share this folder
  • Optional: If your PC is in domain/has multiple users/separate docker user then go to Permissions, add your account/docker account with full controll
  • Go to Docker > Settings > Shared drives > Check S:
  • Done

Now you can use the S: drive for docker containses, like: -v /s/nexus31/nexus-data:/nexus-data, or from Kitematic > Settings > Volumes.

Auto mount VHD

Task Scheduler

And it is still not enough. You have to configura a task, which auto-mount the VHD on startup. For this, you can use a batch file, such as:

@echo off
SET TEMPFILE="%TEMP%%RANDOM%.TXT"
echo SELECT VDISK FILE=‪E:\VMs\docker\shared.vhd >%TEMPFILE%
echo ATTACH VDISK>>%TEMPFILE%
DISKPART /s %TEMPFILE%
del %TEMPFILE%

Open task scheduler, and set up a new task to run this file on startup (http://woshub.com/auto-mount-vhd-at-startup/)

Other

Or you could just use some utility programs: https://www.medo64.com/vhdattach/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment