Windows Host Docker + WSL2 - How to mount Windows directory to a Linux container

Viewed 2584

I am running Windows 10 as my host, and I am trying to mount a Windows directory into a Linux container (node, Debian based).

Previously, I was using Hyper-V backend and the dockerode package to interact with the Docker daemon to mount my Windows directory into my container. I could create a Docker volume by passing in a Driver opt lines of:

device: /host_mnt/d/path/to/my/dir

The keyword here being /host_mnt.

I am moving my development to using Docker dev containers and WSL2, however, the host_mnt path is no longer recognised. What is the correct path to mount a host Windows directory into my Linux container? I a running Docker Engine v20.10.3, Use the WSL 2 based engine is activated in my Docker settings and I am running Docker desktop 3.2.0 (61504).

1 Answers

After some intense Googling / StackOverflowing, I found the magic incantation.

/run/desktop/mnt/host/${driveLetter}/path/to/my/windows/dir

Where ${driveLetter} is the drive letter in Windows but lower case (e.g. c, d, e, etc.)

Maybe I missed some documentation somewhere but now I can run my Node container on a Windows Host, and just mount my files from the Windows host directly into my container.

Edit:

Context:

My project is running a Node backend container, that has access to the Docker Daemon to spin up other containers. This container can spawn new containers (by making a call to the Docker daemon) and stop containers. Another responsibility is to mount some directories to the new containers.

We usually deploy on a Linux environment but for local development, we use Windows. So we don't usually care about this unless we're writing new code / debugging. We mount some local Windows directories into the new spawned container (which is what I wanted to do with the original question). Through Node and Dockerode, we make a call to the Docker Daemon to the create Container endpoint, with a HostConfig->Mounts->VolumeOptions->DriverConfig with the path in Windows.

Related