Normally, when finding a bind-mount path for the overlay2 driver with Docker-in-Docker, I can do it via the following:
$ docker run --rm -it --entrypoint bash \
-v /var/run/docker.sock:/var/run/docker.sock \
gcr.io/cloud-builders/docker
$ apt-get install jq -y
$ mount_point=$(docker inspect $HOSTNAME | jq -r '.[0].GraphDriver.Data.MergedDir')
$ echo "$mount_point"
/var/lib/docker/overlay2/c68a6fc53a27d6347e691a52bdd792094a7a4fdc65041b387d1ea38607ba999d/merged
$ mkdir hello && cd hello
$ echo "sample contents" > file
$ docker run --rm -it --entrypoint bash \
-v "$mount_point/hello":/hello \
-w /hello \
gcr.io/cloud-builders/docker
$ ls
# nothing
For everything besides WSL2, this will properly mount my files. However, for WSL2, it seems the bind mounts are present under a different location. If my attached WSL2 distro name is Ubuntu-22.04, I can find a list of unique IDS under /mnt/wsl/docker-desktop-bind-mounts/Ubuntu-22.04/:
$ ls /mnt/wsl/docker-desktop-bind-mounts/Ubuntu-22.04/
13a7bc88b63d361f5752d7ef3f5c96cd262ef580e6f435cced6bd10ec82842b0 692b88d87549cc6cb71d70e56b24d64d46c6e4f3b54611d635e407941a34d5da
21241f82d3c1e170eae05d87ed4fe9493165603a5f20f4decc5da0695296a22b 71329c4cc6e32171553fa81d044eb31d1a3aac52ba9376c4a99f4505c494cf5b
2af2028475f25893cbe6ae56fd41a5060323a05cf2de361ca5cd788882ab124e 9f9cdad793414edd07516ebe0fef99bea77a67d7033bcce9e6e2636fc52d206f
40072ee5313e41a68b132298796cbec4d044881a473056704dbaf45732b96709 e9b0d5f175dde593817759ef48c2ea4be074dd6fd7dde1e5ee0051f1cbbb36e7
449de67da5b95f36f74bf415852073e587a6f2f5acffecd8470687a065aa9a24 fd27f4eaa94fe2d4e43106f3751004bf816189bf06237c658a0c8e7aec6e54c8
67aa8dec46ea42423b4090c10503d733f4ff4c1eb43cb8e31f040c84cafba60c
Now, if I use a bindmount for the initial load, I can find the file as the mount point in the container, so at least I can get files relative to a mount point (but not very reliably). Run on the WSL2 host:
$ find /mnt/wsl/docker-desktop-bind-mounts/Ubuntu-22.04 -name clippy.toml
/mnt/wsl/docker-desktop-bind-mounts/Ubuntu-22.04/b7371a7ca29bc7acbea2f7cebdf0d5b452a4fadd8af16a733896e7dccbd49e3a/clippy.toml
/mnt/wsl/docker-desktop-bind-mounts/Ubuntu-22.04/0157aea7f7f54b90e62c5810422a2535f5513005a8db7001cf10c7753d3dc6fb/clippy.toml
This isn't straightforward if more than 1 container or bind mount exists with that file, however. Also, none of the hashes for the container match the Docker inspect or the hostname. Now, run on the container:
$ correct_id=b7371a7ca29bc7acbea2f7cebdf0d5b452a4fadd8af16a733896e7dccbd49e3a
$ echo $HOSTNAME
dadd6ab5f853
$ docker inspect $HOSTNAME| grep b737
# nothing
So there doesn't seem to be a reliable way to find that file. Also, for any files outside a bind mount, there doesn't seem to be a way to find their path. At least, however, the correct WSL2 bind mount location does work if passed into the container:
$ docker run --rm -it --entrypoint bash \
-v /mnt/wsl/docker-desktop-bind-mounts/Ubuntu-22.04/b7371a7ca29bc7acbea2f7cebdf0d5b452a4fadd8af16a733896e7dccbd49e3a/:"$PWD" \
-w "$PWD" gcr.io/cloud-builders/docker
$ ls
CHANGELOG.md Cargo.lock LICENSE-APACHE README.md ci crosstool-ng docker rustfmt.yml target
CODE_OF_CONDUCT.md Cargo.toml LICENSE-MIT assets clippy.toml deny.toml docs src xtask
But how do I find say, a file in the container at /hello/file, which was created inside the container run within WSL2?
I should also mention this is Docker Desktop for Windows being shared into the WSL Ubuntu distro. Docker was not installed inside the distro and then used without iptables.