Using Docker for windows to volume-mount a windows drive into a Linux container
Asked Answered
P

2

12

I'm using Docker Desktop for Windows and I want to find where the volumes are created by Docker, in a Linux container?

Has anyone been able to perform the volume mounting that I am trying to achieve?

Promulgate answered 29/3, 2020 at 15:17 Comment(0)
B
31

If you're just trying to mount a windows path to a Linux based container, here's an example using the basic docker run command, and a Docker Compose example as well:

docker run -d --name qbittorrent -v '/mnt/f/Fetched Media/Unsorted:/downloads' -v '/mnt/f/Fetched Media/Blackhole:/blackhole' linuxserver/qbittorrent

This example shares the f:\Fetched Media\Unsorted and f:\Fetched Media\Blackhole folders on the Windows host to the container; and within the Linux container you'd see the files from those Windows folders in their respective Linux paths shown to the right of the colon(s).

i.e. the f:\Fetched Media\Unsorted folder will be in the /downloads folder in the Linux container.

*First though, make sure you've shared those Windows folders within the Docker Desktop settings area in the GUI.


Update for WSL(2):

You don't need to specifically share the Windows folder paths; that's only needed when not using WSL.


Update:

This seems to be a popular answer, so I thought I'd also include a Docker Compose version of the above example, for the sake of thoroughness (includes how to set a path as read-write (rw), or read-only (ro)):

qbittorrent:
  image: 'linuxserver/qbittorrent:latest'
  volumes:
    - '/mnt/f/Fetched Media/Unsorted:/downloads:rw'
    - '/mnt/f/Fetched Media/Blackhole:/blackhole:rw'
    - '/mnt/e/Logs/qbittorrent:/config/logs:rw'
    - '/opt/some-local-folder/you-want/read-only:/some-folder-inside-container:ro'
Blagoveshchensk answered 29/3, 2020 at 16:52 Comment(4)
I scoured the internet everywhere for this. Thank you so much. Really surprised it's not in Docker documentationSohn
is it possible to do this with a shared network drive? when i have tried the resulting mapped folder comes up emptyBoon
@Boon Loaded question! lol. Take a look here: forums.docker.com/t/…Blagoveshchensk
From a clean Windows 11 install of Docker Desktop for Windows and WSL 2 with no distro like Ubuntu installed, it didn't recognize /mnt. Starting straight from the drive letter worked: /f/Fetched Media/UnsortedDisseminate
A
11

I'm not certain why this was needed, but in the event someone else runs into this problem: I had to put the entire volume declaration in double quotes as follows

docker run -d --name qbittorrent -v "/mnt/f/Fetched Media/Unsorted:/downloads" -v "/mnt/f/Fetched Media/Blackhole:/blackhole" linuxserver/qbittorrent

Otherwise, J. Scott Elblein's answer worked perfectly!

Aguirre answered 3/9, 2020 at 14:25 Comment(2)
You're correct; sometimes it helps to extend the last quote all the way to the end so the entire string is quoted. I usually find this to be necessary if there's a strange character in one of the paths, like a dot, in the case of a hidden folder.Blagoveshchensk
Note: to avoid any possible confusion, I just updated my answer to reflect your answer as well. :)Blagoveshchensk

© 2022 - 2024 — McMap. All rights reserved.