Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access docker data from linux wsl2

I'm running Docker on windows using WSL2. The docker data directory can be access from windows using this path:

\\wsl.localhost\docker-desktop-data\version-pack-data\community\docker

But when I try to access the same folder from WSL, I couldn't find it.

From the linux terminal, I can find the following directory:

/mnt/wsl/docker-desktop-data/version-pack-data

However, it's empty! it doesn't show community folder or any other folders inside of it!

OS: Windows 11 build 10.0.22000.176 Docker: version 20.10.8, build 3967b7d Docker Desktop: Version 4.0.0

like image 991
Menas Avatar asked Sep 07 '25 05:09

Menas


2 Answers

For some reason, you have to re-mount it on a different path like this:

  1. In powershell:
net use h: \\wsl$\docker-desktop-data
  1. In wsl:
sudo mkdir /mnt/yourdockermount
sudo mount -t drvfs h: /mnt/yourdockermount

Source: https://github.com/microsoft/WSL/discussions/4176#discussioncomment-831817

The above worked for me. It was also suggested to do it in one step like so:

In wsl: sudo mount -t drvfs '\\wsl$\docker-desktop-data' /mnt/yourdockermount

Source: https://github.com/microsoft/WSL/discussions/4176#discussioncomment-1458301

like image 83
ADJenks Avatar answered Sep 11 '25 12:09

ADJenks


Slightly older question dusted off by @ADJenks' answer, which certainly will work.

But IMHO a better solution is the one I detail in this Super User answer. Since that's a fairly long read, I'll repeat it here. From inside a WSL2 distribution:

$ 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

The advantage here is that you will be using the native Ext4 filesystem. Using drvfs will not provide native permissions, symlinks, and other POSIX features.

like image 22
NotTheDr01ds Avatar answered Sep 11 '25 11:09

NotTheDr01ds