Windows Host Docker + WSL - Volume mounting issue

Viewed 6723

thx to corona - most of us working from home and due to some convenience, i want to use my windows machine that i have here at home.

I do run Win10 with DockerDesktop Version 2.3.0.3 with Engine running on Version 19.03.8. What I am doing is exposing the docker deamon on localhost in order to use it from my WSL (Version 1, not 2) installed Ubuntu. Docker itself works, I can pull images and do basic stuff. But I am facing issues when mounting volumes :-/

When I try to run my docker-compose up command, it fails with the following error:

ERROR: for my-service  Cannot start service my-service: error while mounting volume '/var/lib/docker/volumes/someDir/_data': failed to mount local volume: mount /home/myUser/myLocalDirectory:/var/lib/docker/volumes/someDir/_data, flags: 0x1000: no such file or directory

The directory /home/myUser/myLocalDirectory does exist. Directory /var/lib/docker/volumes/someDir/_data does not exist on my WSL "host". There is only a /var/lib/docker-engine/... folder, which is obviously not the one i am looking for :-/

My working path is /mnt/e/projects/myDockerProject - but i also tried to mount/bind the folder/harddrive like shown here.

All does not work and i am really stuck - do you have any suggestions/explanations?

2 Answers

When I run a linux container using Docker for Windows, I bind-mount c:/the/windows/path:/desired/path/in/the/container.

There's a lot of layers here:

         ___ WSL
        /
Windows
        \___ Docker Linux VM -- Containers

Under "normal" circumstances (linux host with linux containers), you bind mount a local directory. In the diagram above, that would correspond to a directory in the Docker Linux VM. But Docker for Windows allows us to specify a windows path instead.

When you throw WSL into the mix, things get a bit muddier. Within WSL, /home is already some kind of magic that isn't shown to be directly linked to the c drive:

root@MyPcName:~# df
Filesystem     1K-blocks      Used Available Use% Mounted on
rootfs         498557588 390255608 108301980  79% /
root           498557588 390255608 108301980  79% /root
home           498557588 390255608 108301980  79% /home
data           498557588 390255608 108301980  79% /data
cache          498557588 390255608 108301980  79% /cache
mnt            498557588 390255608 108301980  79% /mnt
none           498557588 390255608 108301980  79% /dev
none           498557588 390255608 108301980  79% /run
none           498557588 390255608 108301980  79% /run/lock
none           498557588 390255608 108301980  79% /run/shm
none           498557588 390255608 108301980  79% /run/user
cgroup         498557588 390255608 108301980  79% /sys/fs/cgroup
C:\            498557588 390255608 108301980  79% /mnt/c

/home obviously corresponds to C:\Users, but you can't tell from the output of df or the contents of /proc/mounts or /etc/fstab.

I would suggest that you try the following:

  1. Specify the windows path: C:/Users/myUser/myLocalDirectory:/desired/path/in/the/container
  2. Specify the WSL path starting with the "base" windows drive: /mnt/c/Users/myUser/myLocalDirectory:/desired/path/in/the/container
  3. If neither of those work, launch docker-compose up from a DOS or powershell prompt, and use the windows path as in #1 above

I was facing a similar issue:

[+] Running 0/1
⠹ Container mysqllocal  Creating                    0.2s
Error response from daemon: failed to mount local volume: mount
/run/desktop/mnt/host/wsl/docker-desktop-bind-mounts/Ubuntu-20.04/0728c21eeaba2a2ed809c50fb993ad2a7f00d011276b110991eafe61e99bbd25:/var/lib/docker/volumes/mysql-volume/_data, flags: 0x1000: no such file or directory

In my case after the docker volume prune the docker volume ls shows no volumes but the docker desktop interface still have volumes listed.

The issue was fixed after removing the volumes using the docker desktop interface.

Related