support native volume bind in another WSL distribution
Is your feature request related to a problem? Please describe
support native volume bind in another WSL distribution.
#
➜ docker run -v /home/bingo/myWork:/myWork --rm busybox:latest ls /myWork
Error: statfs /home/bingo/myWork: no such file or directory
# using windows mount as temporary solution
➜ mkdir -p /mtn/d/d12/mywork && sudo mount --bind /mnt/d/d12/myWork /home/bingo/myWork
docker run -v /mtn/d/d12/mywork:/myWork --rm busybox:latest ls /myFolder
Describe the solution you'd like
As seen previously with Docker Desktop, effortlessly integrating selected WSL environments became feasible after specifying respective WSL contexts If it aligns with future plans, incorporating analogous capabilities within Podman would undoubtedly prove beneficial to wsl users, myself included.
Describe alternatives you've considered
At present, mitigation efforts involve sharing volume in WSL through the Windows host at /mnt, thus allowing interaction via the podman remote tool across distinct WSL environments.
However in this method, there is bound to be a noticeable decline in both reading and writing performance compared to directly engaging with the \\wsl$ drive. Moreover, manual steps involving switching working directories is very inconvenient.
It is possible to store your project files on a mounted drive, but your performance speed will improve if you store them directly on the \wsl$ drive.
Additional context
refer:
- https://podman-desktop.io/docs/podman/accessing-podman-from-another-wsl-instance
- https://github.com/containers/podman/discussions/13537
- https://learn.microsoft.com/en-us/windows/wsl/filesystems#file-storage-and-performance-across-file-systems
moving to podman repository
A friendly reminder that this issue had no activity for 30 days.
This is an absolute must for switching to Podman from Docker.
This issue requests the same feature: https://github.com/containers/podman/issues/25085
I assume the use case involves mounting the content of a folder from a WSL instance (not the podman-machine WSL instance, a distinct one) within a container.
That implies that:
- The WSL instance file system is bind-mounted in
\\wsl$(for example via/etc/fstabunder/mnt/wsl/instances/$WSL_DISTRO_NAME) - The
podmanclient transforms a WSL path (e.g.,/home/bingo/myWork) into the path under the\\wsl$mount (e.g.,/mnt/wsl/<distroname>/home/bingo/myWork)
@bingoct @EdanBrooke @D1StrX, am I correct? And how does the podman client determine that /home/bingo/myWork needs to be translated and is not local to the podman machine's file system?
I believe the \\wsl$ thing refers to a different mechanism, the 9p sharing with windows. But otherwise your concept is correct. I would need to test again with docker desktop to verify but I'm not sure if it bind mounts the entire wsl instance filesystem or (more likely) just bind mounts the individual volume directories as needed when running a container.
This might be useful to know/confirm, so we don't have to completely reinvent the wheel; Docker Desktop and WSL mounts do this according to chatgpt.
Here's what happens:
- $(pwd)/test.config is a WSL path, like /home/you/test.config.
- Docker CLI forwards this to the Docker VM.
- Docker Desktop mounts that file using 9p or virtiofs, effectively making it available inside the VM.
- Docker in the VM mounts it into the container.
The VM is configured to know how to find WSL file paths, using: \wsl${distro}\path (Windows view) and internally using Plan 9 (9p) or virtiofs for file access.
File Sync Optimization
Docker Desktop also:
-
Uses cached mount options (:cached, :delegated) to optimize access.
-
Monitors and syncs file changes between the WSL path and the container mount.
Personal opinion
I am personally not a big fan of the file sync optimizations, since these can grow the vhd of Docker/podman-machine a lot.
If podman-machine could access the source WSL (where the podman mount command runs) and the performance is good, I'd prefer that.
What Podman Lacks (Currently according to chatgpt)
Podman does not yet have:
- A full dockerd-like VM + filesystem bridge.
- Automatic 9p/virtiofs file sharing from WSL.
- A socket/CLI bridge that handles WSL path translation.
That's incorrect, at least with regards to mounting from one WSL instance to another. 9p and the virtio system is slow, so it's only used for mounting windows only directories into the docker WSL instance. From other WSL instances they are bind mounted into the shared WSL directory thus making them available in all instances including the docker instance.
Ok I did some quick tests with Docker desktop:
base docker mounts (as seen from default WSL instance)
$ grep docker-desktop /proc/self/mountinfo
431 74 7:0 / /mnt/wsl/docker-desktop/cli-tools ro,relatime shared:167 - iso9660 /dev/loop0 ro,nojoliet,check=s,map=n,blocksize=2048,iocharset=iso8859-1
1123 74 0:62 /docker.sock /mnt/wsl/docker-desktop-bind-mounts/Ubuntu/71329c4cc6e32171553fa81d044eb31d1a3aac52ba9376c4a99f4505c494cf5b rw,nosuid,nodev shared:20 - tmpfs none rw,mode=755
...
Note that both the docker socket and CLI tools are bind mounted from the docker WSL instance
running docker from default WSL instance
~/tmptst$ docker run --rm -d -v .:/test alpine sleep 120
dc7d801feb9fde4348a495aa367b273f46b550dc5c1c6c161c9ab18e8dbaaa9d
~/tmptst$ docker run --rm -d -v $PWD/a:/test2 alpine sleep 120
f1c280e6a609c084b92c589ff30d6eb5ada65fcda9dbebc18fd02d1625ea16ce
~/tmptst$ docker run --rm -i -v ./b:/test3 alpine sh -c 'grep test3 /proc/self/mountinfo && sleep 120'
1677 1654 8:32 /home/computator/tmptst/b /test3 rw,relatime - ext4 /dev/sdc rw,discard,errors=remount-ro,data=ordered
Note that for test3 the correct mount paths appear from inside the container with no path modifications despite the container process running in a separate WSL instance
resulting mounts (default WSL instance's perspective)
$ grep tst /proc/self/mountinfo
1206 74 8:32 /home/computator/tmptst /mnt/wsl/docker-desktop-bind-mounts/Ubuntu/a2f3afabaa2c8b92b633ea6b02e0562d4b407bc58c6da53a593d730730252b77 rw,relatime shared:460 - ext4 /dev/sdc rw,discard,errors=remount-ro,data=ordered
1231 74 8:32 /home/computator/tmptst/a /mnt/wsl/docker-desktop-bind-mounts/Ubuntu/82526405d047aa8a5a054463dd68620cec6d569b51d8a8ea02ff9858d8c58232 rw,relatime shared:468 - ext4 /dev/sdc rw,discard,errors=remount-ro,data=ordered
1222 74 8:32 /home/computator/tmptst/b /mnt/wsl/docker-desktop-bind-mounts/Ubuntu/410f86b75dcbcaad25c7ead8d57bdb88c030255f69fe634b23acfc13fb279513 rw,relatime shared:463 - ext4 /dev/sdc rw,discard,errors=remount-ro,data=ordered
Docker seems to create a new unique ID and bind mount for each individual volume in a container to keep track of paths across WSL instances.
related mounts from the perspective of the docker WSL instance
# grep tst /proc/self/mountinfo
1215 452 8:32 /home/computator/tmptst /tmp/docker-desktop-root/mnt/host/wsl/docker-desktop-bind-mounts/Ubuntu/a2f3afabaa2c8b92b633ea6b02e0562d4b407bc58c6da53a593d730730252b77 rw,relatime shared:460 - ext4 /dev/sdc rw,discard,errors=remount-ro,data=ordered
1213 439 8:32 /home/computator/tmptst /mnt/host/wsl/docker-desktop-bind-mounts/Ubuntu/a2f3afabaa2c8b92b633ea6b02e0562d4b407bc58c6da53a593d730730252b77 rw,relatime shared:460 - ext4 /dev/sdc rw,discard,errors=remount-ro,data=ordered
1211 192 8:32 /home/computator/tmptst /mnt/host/wsl/docker-desktop-bind-mounts/Ubuntu/a2f3afabaa2c8b92b633ea6b02e0562d4b407bc58c6da53a593d730730252b77 rw,relatime shared:460 - ext4 /dev/sdc rw,discard,errors=remount-ro,data=ordered
1278 452 8:32 /home/computator/tmptst/a /tmp/docker-desktop-root/mnt/host/wsl/docker-desktop-bind-mounts/Ubuntu/82526405d047aa8a5a054463dd68620cec6d569b51d8a8ea02ff9858d8c58232 rw,relatime shared:468 - ext4 /dev/sdc rw,discard,errors=remount-ro,data=ordered
1276 439 8:32 /home/computator/tmptst/a /mnt/host/wsl/docker-desktop-bind-mounts/Ubuntu/82526405d047aa8a5a054463dd68620cec6d569b51d8a8ea02ff9858d8c58232 rw,relatime shared:468 - ext4 /dev/sdc rw,discard,errors=remount-ro,data=ordered
1274 192 8:32 /home/computator/tmptst/a /mnt/host/wsl/docker-desktop-bind-mounts/Ubuntu/82526405d047aa8a5a054463dd68620cec6d569b51d8a8ea02ff9858d8c58232 rw,relatime shared:468 - ext4 /dev/sdc rw,discard,errors=remount-ro,data=ordered
1232 452 8:32 /home/computator/tmptst/b /tmp/docker-desktop-root/mnt/host/wsl/docker-desktop-bind-mounts/Ubuntu/410f86b75dcbcaad25c7ead8d57bdb88c030255f69fe634b23acfc13fb279513 rw,relatime shared:463 - ext4 /dev/sdc rw,discard,errors=remount-ro,data=ordered
1229 439 8:32 /home/computator/tmptst/b /mnt/host/wsl/docker-desktop-bind-mounts/Ubuntu/410f86b75dcbcaad25c7ead8d57bdb88c030255f69fe634b23acfc13fb279513 rw,relatime shared:463 - ext4 /dev/sdc rw,discard,errors=remount-ro,data=ordered
1227 192 8:32 /home/computator/tmptst/b /mnt/host/wsl/docker-desktop-bind-mounts/Ubuntu/410f86b75dcbcaad25c7ead8d57bdb88c030255f69fe634b23acfc13fb279513 rw,relatime shared:463 - ext4 /dev/sdc rw,discard,errors=remount-ro,data=ordered
This is more of an implementation detail, but the 3 separate mounts for each path seem likely to be due to docker mapping the path to two other locations to help with mount namespaces or something for the created containers.
Note that all of these (except the base docker mounts) use the same 8:32 major/minor number because they are all just bind mounts of the same filesystem. No additional filesystems such as 9p are involved.
Also #25085 seems like a duplicate of this ticket
Thank you @computator. This is valuable information. I will also experiment with Docker to gather additional details and find a compatible solution. And, of course, the point here is to avoid 9p to get a decent I/O throughput.
I have one more question, though. In your example, you are running the Docker client from a WSL instance; there is no expectation to have such behavior when running the Windows client, right? In other words, running
docker.exe run --rm -d -v /home/computator/tmptst:/test alpine sleep 120
from a Windows terminal doesn't work. The Docker/Podman client must be executed from the target WSL instance.
That is correct. When running it directly from Windows outside of a WSL instance it only has access to the Windows filesystem. /home/computator/tmptst is not a valid Windows path (UNC or otherwise). For Windows paths it can just use the built in support for accessing the Windows filesystem via /mnt/c/whatever/.... I believe Podman already has built in support for that. If you use -v with a Windows or UNC path I believe Podman will translate it to the correct /mnt/c/... path.
se the built in support for accessing the Windows filesystem via /mnt/c/whatever/.... I believe Podman already has built in support for that. If you use -v with a Windows or UNC path I believe Podman will translate it to the correct /mnt/c/... path.
Correct, this is already supported. And when it's not a valid Windows path we assume that's a valid path in the WSL instance and it's not transformed. But this is a different scenario, not related to this issue. Thank you for making it clear.
For anyone interested, here is a draft of a solution to address this issue. Any feedback is welcome.
In the meantime, a workaround is to use a script that mounts the folder (I called podpath and saved it in ~/.bin/):
cat << 'EOF' > ~/.bin/podpath
#!/usr/bin/env bash
set -euo pipefail
source=$(realpath ${1})
distro=${WSL_DISTRO_NAME}
source_sha256=$(echo -n "${source}" | sha256sum -z | head -c 64)
target="/mnt/wsl/podman-bind-mounts/${distro}/${source_sha256}"
mkdir -p "${target}"
sudo mount --bind "${source}" "${target}"
echo "${target}"
EOF
Once the script is executable and added the folder to $PATH
chmod +x ~/.bin/podpath
export PATH=${PATH}:~/.bin/
It's possible to use it to mount a volume (use -v $(podpath <path>) rather than -v <path>) :
podman run -ti --rm -v "$(podpath ~/foo)":/foo/ fedora ls -la /foo/
⚠ The podpath script executes the mount command with sudo, hence users may be prompted for their password
⚠ Again: that's not a proper solution, but can be used as a workaround. A proposal of a proper solution is described draft
For anyone interested, here is a draft of a solution to address this issue. Any feedback is welcome.
I was reading the draft. Why is it needed to share the binary executable for podman-remote across machines?
I was reading the draft. Why is it needed to share the binary executable for
podman-remoteacross machines?
- To avoid that users have to install Podman twice: in the Windows host and in the WSL distribution. When Podman is installed in the Windows host, it will be also available on every WSL distribution too.
- To match the version of podman in the WSL distribution with the version of the podman in the podman machine.
To avoid that users have to install Podman twice: in the Windows host and in the WSL distribution. When Podman is installed in the Windows host, it will be also available on every WSL distribution too
Mmmh... I normally configure CONTAINER_HOST env var to leverage the windows podman among all WSL. Will using the windows executable correctly mount / access WSL files and with the right performance?
To match the version of podman in the WSL distribution with the version of the podman in the podman machine.
I suppose there's a degree of backwards compatibility (e.g. Semantic versioning)? I'd honestly let this being handled by the specific distribution.
To match the version of podman in the WSL distribution with the version of the podman in the podman machine.
I suppose there's a degree of backwards compatibility (e.g. Semantic versioning)? I'd honestly let this being handled by the specific distribution.
Docker desktop shares the binaries from it's WSL instance with the other instances. It makes it easier because you always know you have a compatible, up to date version, and don't need to have the same thing installed multiple places. That does not prevent you from installing a separate version in a particular WSL instance with the package manager or something if you want to.
Hi, just checking in to see if there's been any feedback on this proposal. I haven't contributed to podman before, but would be willing to help with the implementation.
@zbreit, we haven't found an agreement on the design. I will bring up this topic at the next community call.