5

The Context

I understand that docker-desktop's WSL2 backend works by creating 2 distros: docker-desktop & docker-desktop-data.

I can see the filesystems of these distros mounted in my Ubuntu WSL2 distro:

grant@BeastMini-II:~$ ls -l /mnt/wsl
total 4
drwxr-xr-x 4 root root 100 Apr  1 09:12 docker-desktop
drwxr-xr-x 3 root root  60 Apr  1 09:12 docker-desktop-bind-mounts
drwxr-xr-x 4 root root  80 Apr  1 09:12 docker-desktop-data
-rw-r--r-- 1 root root 197 Apr  1 09:12 resolv.conf

When I view docker-desktop-data through Powershell I can see the various files in the filesystem:

PS C:\Users\grant> ls \\wsl$\docker-desktop-data


    Directory: \\wsl$\docker-desktop-data


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d-----        01/02/2023     18:36                lost+found
d-----        01/02/2023     18:36                .docker
d-----        01/02/2023     18:36                tmp
d-----        01/04/2023     09:12                etc
d-----        01/02/2023     18:36                isocache
d-----        01/04/2023     09:12                run
d-----        01/02/2023     18:36                sbin
d-----        01/02/2023     18:36                data
d-----        01/02/2023     18:36                bin
d-----        01/02/2023     18:36                mnt
d-----        01/04/2023     09:12                sys
d-----        01/02/2023     18:36                usr
d-----        01/04/2023     09:12                proc
d-----        01/04/2023     09:12                dev
------        26/01/2023     12:11        1813552 wsl-keepalive
------        01/01/1970     00:00        1955960 init

... but when I view the mounted filesystem in Ubuntu I only see a small subset of the filesystem:

grant@BeastMini-II:~$ ls -l /mnt/wsl/docker-desktop-data
total 4
drwxr-xr-x 2 root root   40 Apr  1 09:12 data
drwxr-xr-x 3 root root 4096 Feb  1 18:36 isocache

The Question(s)

Why do I not see the entire filesystem at /mnt/wsl/docker-desktop-data in my Ubuntu WSL2 distrobution?

What determines what files will and will not show up in that mounted directory?

In a running distro - how is /mnt/wsl/docker-desktop-data different from /some/mount/path after you have mounted docker-desktop-data to it manually with sudo mount -t drvfs '\\wsl$\docker-desktop-data' /some/mount/path? I can clearly see more of the filesystem in the latter.

What is not the Question

How to view the entire docker-desktop-data directory in a WSL2 distro - I already know that I can mount it with `sudo mount -t drvfs '\wsl$\docker-desktop-data' /some/mount/pat

1
  • Have you tried sudo ls in Ubuntu ?
    – harrymc
    Commented Apr 12, 2023 at 8:12

1 Answer 1

3
+100

Note: The information in this answer has been validated against WSL 1.2.0 and Docker Desktop 4.18.0. The methods discussed below have changed in the past and will likely change again in the future.

In a WSL2 distro - what determines the files that appear under: /wsl/{some-other-distro}

The question title is a bit ambiguous. I believe you are asking about /mnt/wsl/{some-other-distro}, but you left out the /mnt part. Or you could be asking about the \\wsl.localhost\<distro> share (a.k.a. \\wsl$\<distro>).

For the latter, the rootfs for the distribution is provided as a share through \\wsl.localhost (the now-preferred version over the deprecated, but still available, \\wsl$\).

For /mnt/wsl, there is no automatic process for this - Each distribution (and even the end-user) can mount whatever they like under /mnt/wsl. Docker chooses to do so in its startup, but you can also create your own mounts using something like my answer here.

For /mnt/wsl itself, there are a few files that WSL automatically generates there so that they are available in all distributions:

  • resolv.conf - The automatically generated resolver configuration, which is then symlinked into /etc/resolv.conf.

  • (In the latest versions of WSL): /mnt/wsl/run and /mnt/wsl/user which are then bind-mounted into their respective directories.

Why do I not see the entire filesystem at /mnt/wsl/docker-desktop-data in my Ubuntu WSL2 distribution?

In a running distro - how is /mnt/wsl/docker-desktop-data different from /some/mount/path after you have mounted docker-desktop-data to it manually with sudo mount -t drvfs '\\wsl$\docker-desktop-data' /some/mount/path? I can clearly see more of the filesystem in the latter.

As you've noticed (or at least assumed), Docker Desktop does not mount the virtual drive for docker-desktop-data itself. Instead, it creates a bind-mount to a subdirectory of that drive (and a number of other bind-mounts to other subdirectories). At a high level, docker-desktop-data seems to use a technique similar to the one in my answer on sharing files between distributions, in that, when starting up, it creates a bind-mount for the primary "shared directory."

From a regular WSL distribution, you can see the actual mount with:

$ findmnt | grep "version-pack-data\s"

| |-/mnt/wsl/docker-desktop-data/version-pack-data        /dev/sdf[/version-pack-data]          ext4          rw,relatime,discard,errors=remount-ro,data=ordered

In this case, dev/sdf has been assigned to the virtual drive for the docker-desktop-data distribution. That may change depending on the order in which you start distributions (and how many).

If we could access the docker-desktop-data distribution directly, that would be the equivalent of running (as root):

mount --bind / /mnt/wsl/docker-desktop-data/version-pack-data -o X-mount.mkdir

And while you may already know this, for other readers, note that /mnt/wsl is a tmpfs that is created by WSL itself on each startup. It is shared and accessible in all WSL distributions, and it is ephemeral -- Its contents (the mountpoints, not the data under them) will be removed each time WSL shuts down.

What determines what files will and will not show up in that mounted directory?

With the above in mind, it should be apparent that what you see in /mnt/wsl/docker-desktop-data is a combination of each of the bind-mounts, with the primary one being version-pack-data.

With a full findmnt, you'll notice a number of other docker-desktop-data mounts as well. While reverse-engineering each of these is beyond the scope of any one answer, there are a few interesting ones. From inside docker-desktop, run:

mount | grep iso

This will show you how Docker delivers the executables and libraries themselves. These ISO's can be found in the Windows Docker installation folder (usually C:\Program Files\Docker\Docker\resources). When a new release of Docker comes out, the ISO files are updated with the latest versions and then mounted into WSL.


Side-notes:

  • You'll notice that the mount command only shows /dev/sdf being mounted on /mnt/wsl/docker-desktop-data/version-pack-data. The same thing would happen if you created a bind-mount yourself in your preferred distribution. E.g.:

    $ sudo mount --bind /home /mnt/wsl/test -o X-mount.mkdir
    $ mount | grep home
    # Doesn't find anything
    $ mount | grep test
    /dev/sdc on /mnt/wsl/test type ext4 (rw,relatime,discard,errors=remount-ro,data=ordered)
    

    However, you'll get better info from findmnt (as above) or:

    $ cat /proc/self/mountinfo | grep home
    1734 71 8:32 /home /mnt/wsl/test rw,relatime shared:501 - ext4 /dev/sdc rw,discard,errors=remount-ro,data=ordered
    
  • As you may have realized by now, it's probably better to mount the docker-desktop-data drive as a native ext4 rather than using drvfs:

    $ findmnt -a | grep "version-pack-data\s"
    | |-/mnt/wsl/docker-desktop-data/version-pack-data        /dev/sdf[/version-pack-data]          ext4          rw,relatime,discard,errors=remount-ro,data=ordered
    # Using the block device returned (sdf in this case):
    $ sudo mount /dev/sdf /mnt/wsl/instances/docker-desktop-data -o X-mount.mkdir
    $ cd /mnt/wsl/instances/docker-desktop-data
    

    This will provide native permissions, symlinks, etc.

  • In the latest releases of WSL, more exploration can be performed from the root namespace, a.k.a. the Debug Shell. In an administrative PowerShell, run:

    wsl --debug-shell
    

    This root namespace shows all running processes in each of the distributions, including docker-desktop-data.

    There's only one process running in docker-desktop-data (other than the default init and Plan 9 server, and that's wsl-keepalive. I'm going to assume the obvious given the name -- That this is simply a long-running process to keep docker-desktop-data running and accessible.

    You can demonstrate this with (again, in the debug shell):

    $ cat /proc/$(pgrep wsl-keepalive)/environ | xargs -0 -I{} echo {} | grep WSL_DISTRO_NAME
    WSL_DISTRO_NAME=docker-desktop-data
    

    You can also explore the other distributions namespaces with lsns, nsenter, and others. However, note that the lack of a shell or any other executable in docker-desktop-data seems to preclude using nsenter to explore that particular namespace. However, exploring the /proc/<pid> for that that distribution can still be interesting.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .