question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Volume mount won't remount across docker restart in WSL2

See original GitHub issue

EDIT May 25, 2022

Further testing shows that this bug occurs with any volume mount from a native WSL2 directory, not just ones that have soft links to a Windows directory, as described below. If you mount a WSL2 directory as a volume in a Docker container, it stops working once Rancher is restarted. If you mount a Windows directory as a volume in a Docker container, it will still work after Rancher is restarted.

Actual Behavior

A volume mount which uses a soft link to mount a directory in Windows works OK when container is first run, but does not remount when the container is stopped then restarted.

Mounting a Windows volume in a Docker container doesn’t work when specifying the volume’s path as /mnt/c/Users/... but does work if you soft link from the WSL2 home directory. Unfortunately the container cannot remount the volume after stopping and restarting it.

Steps to Reproduce

$ pwd
/home/xxx

$ ls -lat win
lrwxrwxrwx 1 xxx xxx 46 Apr 21 19:55 win -> '/mnt/c/Users/xxx/projects/'

$ sudo -E /usr/local/bin/docker run -itd --restart=always -v /home/xxx/win:/home/xxx/work -v /var/run/docker.sock:/var/run/docker.sock linux-dev --hostname linux-dev --name linux-dev 
93dc4d62eae20d5de72e8cab1b0db51c1fc188c6c4577db8a4b876cff9a7dc97

$ docker stop linux-dev
linux-dev

$ docker start linux-dev
Error response from daemon: failed to create shim: OCI runtime create failed: container_linux.go:380: starting container process caused: process_linux.go:545: container init caused: rootfs_linux.go:76: mounting "/mnt/wsl/rancher-desktop/run/docker-mounts/aaad516c-8005-484e-be16-b6a867acf089" to rootfs at "/var/run/docker.sock" caused: mount through procfd: not a directory: unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type
Error: failed to start containers: linux-dev

Result

$ docker start linux-dev Error response from daemon: failed to create shim: OCI runtime create failed: container_linux.go:380: starting container process caused: process_linux.go:545: container init caused: rootfs_linux.go:76: mounting “/mnt/wsl/rancher-desktop/run/docker-mounts/aaad516c-8005-484e-be16-b6a867acf089” to rootfs at “/var/run/docker.sock” caused: mount through procfd: not a directory: unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type Error: failed to start containers: linux-dev

Expected Behavior

Container starts with volume mount intact.

Additional Information

No response

Rancher Desktop Version

1.3.0

Rancher Desktop K8s Version

n/a

Which container runtime are you using?

moby (docker cli)

What operating system are you using?

Windows

Operating System / Build Version

OS Name Microsoft Windows 10 Enterprise Version 10.0.19042 Build 19042

What CPU architecture are you using?

x64

Linux only: what package format did you use to install Rancher Desktop?

No response

Windows User Only

No

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:3
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
Maxinho96commented, May 23, 2022

I am experiencing the same bug using bind mounts in docker-compose through WSL2.

0reactions
wolfymastercommented, Nov 30, 2022

Upon further review - I think everything is working correctly - but the issue we are running into is due to mungeContainersStartRequest doing a look-up against the full container id which is stored in docker-binds.json

{
  "159bddfc-dfa4-4938-898c-1c0246e077e7": {
    "ContainerId": "e14f944aedfebf7ce2dfba98ae13450767a2a58dc50d8a87f5e02ac1b5fb7429",
    "HostPath": "/home/wolfy/code/test/"
  },
  ...
} 

If I perform a docker start e14f944aedfebf7ce2dfba98ae13450767a2a58dc50d8a87f5e02ac1b5fb7429 the container comes up with the correct bind mounts - however using any other alias (ie the name or short id) is not found in the map and therefore the binds are not re-created.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Windows Host Docker + WSL - Volume mounting issue
When I run a linux container using Docker for Windows, I bind-mount c:/the/windows/path:/desired/path/in/the/container .
Read more >
Get started mounting a Linux disk in WSL 2
To do this, you first need to mount the VHD into Windows using the Mount-VHD command in Windows. Be sure to run this...
Read more >
podman-run
docker ://docker-reference (Default) An image reference stored in a remote container image registry. Example: “quay.io/podman/stable:latest”. The reference can ...
Read more >
Overview | Docker Documentation
Select the Troubleshoot icon from the Docker Dashboard. Troubleshoot Docker Desktop. The Troubleshoot page contains the following options: Restart Docker ...
Read more >
GitLab Docker images
The GitLab container uses host mounted volumes to store persistent data: ... and permissions cannot be changed without remounting, and GitLab fails.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found