2

I've set up the latest Docker Desktop 2.1.0.5 in Windows 10 and creating and running simple/trivial containers i.e. docker run --rm -v c:/Users:/data alpine ls /data works fine.

However, I'm having trouble (1) creating a volume tied to a folder on the Windows host and asking a Linux container to use it; and (2) specifying a DockerFile for that container. Here's what I tried:

  1. I created a volume via the command docker volume create --driver local --opt type=none --opt device=c:\path\to\folder --opt o=bind test_vol, and tried to mount it like this: docker run --rm -v test_vol:/data alpine ls /data. This gives me the error:

C:\Program Files\Docker\Docker\Resources\bin\docker.exe: Error response from daemon: error while mounting volume '/var/lib/docker/volumes/test_vol/_data': failed to mount local volume: mount c:\path\to\folder:/var/lib/docker/volumes/test_vol/_data, flags: 0x1000: no such file or directory.

However, if I specify that host folder in the docker run command without going through a previously-created volume (like this: docker run --rm -v c:\path\to\folder:/data alpine ls /data) then it works fine.

  1. Specifying a DockerFile is also problematic. If I use this command: docker run --rm --env-file c:\path\to\DockerFile -v c:\path\to\folder:/data alpine ls /data, I get this error:

C:\Program Files\Docker\Docker\Resources\bin\docker.exe: read c:\path\to\DockerFile: The handle is invalid. See 'C:\Program Files\Docker\Docker\Resources\bin\docker.exe run --help'.

  1. For the above, I've tried changing the direction of the slashes (/ vs \) and putting the paths in quotes, but none of that helped or changed the error output.
  2. I made sure that "Shared Drives" is turned ON in Docker Desktop Settings.

I'm very confused about how to specify these paths in Docker for Windows. Can someone please advise on how to troubleshoot this? Thank you.

1 Answer 1

3

TLDR

You should use the /host_mnt/c/path/to/folder path format (notice the lowercase drive letter).


In-depth

Depending on the version of Docker Desktop for Windows, I determined the following regarding path formats:

paths formats for shared volumes across Docker Desktop versions

So using C:\path\to\folder should work on the latest 2.3.0.2 / 2.3.0.3 versions. If you are still on version 2.1.0.5, //C/path/to/folder should work.

If you look at the path when inspecting the created volume (in v2.3.0.3):

path formats at volume creation and inspection

The only path format that stays the same is /host_mnt/c/path/to/folder.

This means, in docker-compose, that if you use any other format and try to reuse an already created volume (i.e. two consecutive up), you get an error:

$ docker-compose up
ERROR: Configuration for volume test_vol specifies "device" driver_opt /C/path/to/folder, but a volume with the same name uses a different "device" driver_opt (/host_mnt/c/path/to/folder). If you wish to use the new configuration, please remove the existing volume "test_test_vol" first:
$ docker volume rm test_test_vol

Conclusion

So to be compatible across all versions and have a satisfactory workflow in Docker Compose, the best bet is to use /host_mnt/c/path/to/folder (notice the lowercase drive letter):

  • docker volume create --driver local --opt type=none --opt device=/host_mnt/c/path/to/folder --opt o=bind test_vol
  • docker run --rm -v test_vol:/data alpine ls /data

Same goes for docker-compose:

version: '3.4'

volumes:
   test_vol:
      driver: local
      driver_opts:
         type: none
         device: /host_mnt/c/path/to/folder
         o: bind

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .