How to access the volume in host in docker for windows

Viewed 5780

I run the docker for Windows and ubuntu in WSL. When I run the following command

docker volume create test
docker volume inspect test

I get the following output

[
    {
        "Driver": "local",
        "Labels": {},
        "Mountpoint": "/var/lib/docker/volumes/test/_data",
        "Name": "test",
        "Options": {},
        "Scope": "local"
    }
]

when I access the location, I get bash: cd: /var/lib/docker/volumes: No such file or directory

So how should I access the folder?

3 Answers

The directory is is protected so you can cd into it, however you can ls the contents:

sudo ls /wsl/docker-desktop-data/data/docker/volumes/test/_data

I've modified my WSL set up as per this article so you may find your path is different. I think the default path is probably /mnt/wsl/docker-desktop-data/data/docker/volumes/test/_data

You might find it more useful to mount a directory in your Windows user folder which can be done by changing the WSL mount point as per the article linked to above and then running:

docker volume create --driver local --name test --opt device=/run/desktop/mnt/host/c/Users/<username>/test --opt type=none --opt o=bind

(assuming you've got a folder called test at the root of your Windows user directory)

based on @nick's answer

  • From linux: sudo ls /mnt/wsl/docker-desktop-data/data/docker/volumes
  • From windows: \\wsl$\docker-desktop-data\mnt\wsl\docker-desktop-data\data\docker\volumes

For me the volumes data are at /mnt/wsl/docker-desktop-data/version-pack-data/community/docker/volumes, each distro may mount wsl at different location, this is the default path for Ubuntu at least.

I can cd into it with root permission.

Related