I just had the most painful experience trying to get this to work, so I thought I’d share what I’ve learned to hopefully spare someone else from similar torture. These issues will almost certainly be sorted out in the next few releases of Docker for Windows, Hyper-V, and Windows 10… but for the moment they seem to be tripping up a *LOT* of people.

The Expectation

Docker provides the concept of Volumes, which supports mapping a directory on the host so that it is accessible as a directory inside the guest. So with “host” being Windows 10 with Docker on Hyper-V, and “guest” being some flavour of Linux, a command line like this:

docker run --name=data-container --rm -it -v c:/data:/var/data data-container

should allow access to the same files from both machines. That is:

  1. when starting up the container, any files that exist at c:\data on the host should also appear at /var/data on the guest
  2. a file added from the host (e.g. echo time >> c:\data\time.txt) while the container is running should immediately show up in the guest at ls /var/data/time.txt
  3. a file added form the guest (e.g. touch /var/data/test.txt) should immediately show up in the host at dir c:\data\test.txt

The Problem

… is that the Docker container is unable to read the contents of a shared host volume.

The reason for failure, as it turns out, is one of authentication/authorisation. I spent a harrowing night trying countless things that reportedly “definitely” solved the issue, only to rinse and repeat. I finally managed to get it working with a lot of help from this (very long) thread (which, by the way, has a lot of those rinse-and-repeat solutions I mentioned).

The Solution

Here’s a summary of the solution (somewhat lengthened by the necessary “cleaning” steps to get to a known good state):

1. Cleaning Up

First, make sure that Docker doesn’t have any shares requested… Open up Docker Settings on the “Shared Drives” tab.

check-shared-drives

  • Un-check all the boxes under the “Shared” column
  • Click “Reset credentials…”
  • Click “Apply”

Next, make sure that none of your drives are shared by the OS… Open up “This PC” in Windows Explorer, and for each drive in turn: right-click the drive icon and select “Properties”; then select the “Sharing” tab.

unshare-windows

  • If the “Network File and Folder Sharing” section shows the drive as “Shared”, click the “Advanced Sharing…” button
  • In the pop-up dialog, un-check the “Share this folder” box, then click “OK”
  • Click “Close”, and repeat for the next drive, until all drives have been un-shared

2. Prepare a User

Open up Computer Management (right click the “Start” button, and choose “Computer Management”).

computer-management

  • Select “System Tools” → “Local Users and Groups” → “Users”
  • From the “Action” menu, select “New User…”
  • Specify the “User Name” (e.g. DockerUser) and “Password”… and confirm the latter
  • Make sure not to use any Unicode characters in the Password field, as this is as yet not supported by Docker
  • Un-check the “User must change password at next logon” box, then check “Password never expires”
  • Click “Create”

new-user

I’ll leave it up to you to interpret the security implications of the above within your own context. Also, the user will need access rights to the drive that you intend to share with the Docker guest, however you choose to assign those. In the case of my local-only development machine context, I simply added DockerUser to the Administrators group, for full access to the root of my data drive.

3. Share the Drives

We’re going to add the user in the context of the host system, as viewed by the Docker guest, so get the IP address for the host … [Ctrl+R] → cmd → [Enter] → ipconfig → [Enter] … it’ll be the one marked DockerNAT (quite probably 10.0.75.1).

Ethernet adapter vEthernet (DockerNAT):

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::d166:82:45b5:40f%9
   IPv4 Address. . . . . . . . . . . : 10.0.75.1
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . :

Finally, head back to the “Shared Drives” tab in Docker Settings

share-drives

  • Check the “Shared” boxes for each of the drives you intend to share with the Docker guest
  • Click “Apply”
  • Enter the username in the format {IP-Address}\{Username} (e.g. in my case 10.0.75.1\DockerUser)
  • Enter the password you assigned during the previous step
  • Click “OK”

set-credentials

Conclusion

At this point, returning to “the expectation” above should result in the correct behaviour.

Hope this helped!