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.
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.
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.
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/)
Or you could just use some utility programs: https://www.medo64.com/vhdattach/