37

I am running Windows Subsystem Linux (WSL) with Ubuntu as client OS under Windows 10. Now I installed Docker Desktop on the Windows host and enabled the WSL integration in the Docker settings. That works fine so far, I can access the Docker daemon running on the Windows host from my WSL Ubuntu client.

Now I am wondering where all the Docker volumes and other data is stored in this setup. Usually these are under /var/lib/docker, but it seems when using WSL this is not the case. When running df -h I can see the following Docker-related lines:

/dev/sdd        251G  3.1G  236G   2% /mnt/wsl/docker-desktop-data/isocache
/dev/sdc        251G  120M  239G   1% /mnt/wsl/docker-desktop/shared-sockets
/dev/loop0      244M  244M     0 100% /mnt/wsl/docker-desktop/cli-tools

So they are somewhere on the Windows host it seems.
... but where?

Matthias
  • 9,307
  • 11
  • 54
  • 109

9 Answers9

100

When I create a volume named shared_data in docker, I can find it under

\\\wsl$\docker-desktop-data\version-pack-data\community\docker\volumes\shared_data\\_data
msanford
  • 11,125
  • 10
  • 64
  • 87
Pierre
  • 1,425
  • 1
  • 11
  • 12
  • Yes, that's the path if you use Docker Desktop on WSL2 (Ubuntu), see : https://stackoverflow.com/a/64418064/6075581 – Connected Wanderer Oct 22 '20 at 19:43
  • Search for this path in windows explorer when docker engine is active – GRANZER Nov 24 '21 at 16:10
  • Can we assume that the standard WSL warning of not editing WSL files through Windows File Explorer still holds for Docker containers? – j08691 Feb 16 '22 at 20:02
  • Note, this is not the same path as /mnt/wsl ... inside WSL, this is only the path as accessed from the Windows 'host' file system – mozboz May 27 '22 at 09:12
42

You can find WSL2 volumes under a hidden network share. Open Windows Explorer, and type \\wsl$ into the location bar. Hit enter, and it should display your WSL volumes, including the ones for Docker for Windows.

Rohaq
  • 1,728
  • 1
  • 14
  • 22
  • 9
    To follow onRohaq's answer...paste this into Windows Explorer to see the data volumes: \\wsl$\docker-desktop-data\version-pack-data\community\docker\volumes PS. I am no Docker expert but this tip helped me greatly. – rr789 Dec 08 '20 at 03:16
11

If you are wondering where on the Windows host the docker volumes are located, for me they seem to be at:

C:\Users\username\AppData\Local\Docker\wsl\data\ext4.vhdx

and

C:\Users\username\AppData\Local\Docker\wsl\distro\ext4.vhdx

presumably, these are docker-desktop-data and docker-desktop respectively.

In theory, these WSL2 instances can be re-located to an alternate drive to free disk space as per this post; that is the standard method for exporting, unregistering, and re-importing an instance from a new location. This process is also described here (with regard to standard WSL instances).

(Caveat - I haven't yet done this with the docker WSL2 instances yet myself, only for Ubuntu using the method in the second link.)

J. Scott Elblein
  • 3,541
  • 11
  • 52
  • 82
Carl Higgs
  • 141
  • 1
  • 7
6

Docker Desktop's WSL2 feature creates two new wsl2 containers docker-desktop and docker-desktop-data, which can be seen by the command wsl -l -v

NAME                   STATE           VERSION
* Ubuntu-18.04           Running         2
  docker-desktop         Running         2
  docker-desktop-data    Running         2

This is where the docker daemon actually runs and where you can find the data you are looking for.

J. Scott Elblein
  • 3,541
  • 11
  • 52
  • 82
danielorn
  • 3,963
  • 1
  • 12
  • 24
4

The volumes in the wsl2 kernel are mapped as follows:

docker run -ti -v host_dir:/app amazing-container will get mapped to /mnt/wsl/docker-desktop-data/data/docker/volumes/host_dir/_data/

The above is the right path, even though docker volume inspect amazing-container will tell you differently (/var/lib/docker/volumes/).

To conclude, the volumes are mapped to: /mnt/wsl/docker-desktop-data/data/docker/volumes/

0x90
  • 37,093
  • 35
  • 149
  • 233
  • How can you query the docker server to return the right path? – Carl in 't Veld Jan 11 '21 at 13:40
  • @Carlin'tVeld replace `/var/lib/docker/volumes/` with `/mnt/wsl/docker-desktop-data/data/docker/volumes/` – 0x90 Jan 11 '21 at 13:44
  • 4
    Well I would like to learn how to pull that data from the Docker server. In the meanwhile I found out that at my side the path is different: \\wsl$\docker-desktop-data\version-pack-data\community\docker\volumes\myvol\_data. Refer to https://github.com/microsoft/WSL/discussions/4176. Strangely when trying to reach out to his folder within wsl2 I find /mnt/wsl/docker-desktop-data/version-pack-data being empty. – Carl in 't Veld Jan 11 '21 at 15:49
  • 1
    @Carlin'tVeld Same for me, I posted an [answer](https://stackoverflow.com/questions/61083772/where-are-docker-volumes-located-when-running-wsl-using-docker-desktop#answer-72307042) with a solution found in the GitHub discussion. – AymDev May 19 '22 at 15:19
2

In my case, i install docker-desktop on wsl2, windows 10 home. i find my image files in

\\wsl$\docker-desktop-data\version-pack-data\community\docker\overlay2

All image files are stored there, and have been seperated into several folders with long string names. When i look into every folder, i can find all the real image files in "diff" folders.
Although the terminal show the path "var/lib/docker", but the folder doesn't exsit and the actual files are not stored there. i think there is no error, the "var/lib/docker" is just linked or mapped to the real folder, kind like that. In windows, we also use mklink to link two folders, it is similar, right?

Json Bourne
  • 109
  • 1
  • 1
  • Indeed, this is correct. The physical images and their layers are organized in this folder. But please note that they work together with /volumes folder as well. – Mário Meyrelles May 17 '21 at 19:58
2

If you are running Docker on Windows host, using Docker Desktop, you can access the volumes at \\wsl$\docker-desktop-data\version-pack-data\community\docker\volumes\ (search this path from windows explorer and make sure docker engine is running).

When running Docker desktop app, the app creates its own Linux VM or using WSL to run the docker container and the path /var/lib/docker/volumes/ is from within that VM I think. The volumes are created as mountable .vhdx file at

C:\Users\username\AppData\Local\Docker\wsl\distro\

but accessing this directly is tricky.

Ref: Google how to access WSl files from Windows

GRANZER
  • 345
  • 3
  • 13
1

You can find volumes and others data when using docker with WSL under docker-desktop-data

volume and other data in docker

Babir
  • 19
  • 3
  • Mine didn't have host, but everything else is the same on my system. Once you get to the docker directory permissions are locked down. I did a `sudo ls volumes` to finally see my data – Ben Ogorek Aug 21 '20 at 15:46
1

Most answers on this topic are about the location from the Windows side, I needed to access the container log files (the issue is the same as for volumes) from my WSL distribution, the Windows path \\wsl$ was not an option.

The files could be found on Windows in \\wsl$\docker-desktop-data\version-pack-data\community\docker\containers.
From the WSL distribution, I could go to /mnt/wsl/docker-desktop-data/version-pack-data but it was empty.

Finally found a solution here:

  1. From Windows, create a disk for docker-desktop-data:
net use w: \\wsl$\docker-desktop-data
  1. From your WSL distribution, mount it to docker:
sudo mkdir /mnt/docker
sudo mount -t drvfs w: /mnt/docker

Now you can get everything you want, in my case log files:

ls -l /mnt/docker/version-pack-data/community/docker/containers/

total 0
drwxrwxrwx 4 root root 512 May 19 15:06 3f41ade0891c06725e828853524d73f185b415d035262f9c51d6b6e03654d505

AymDev
  • 5,278
  • 2
  • 28
  • 46