asuka
asuka

Reputation: 43

How to access the volume in host in docker for windows

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?

Upvotes: 3

Views: 8630

Answers (3)

yume_chan
yume_chan

Reputation: 856

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.

Upvotes: 0

Mahmoud Samy
Mahmoud Samy

Reputation: 2852

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

Upvotes: 2

Nick Graham
Nick Graham

Reputation: 1469

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)

Upvotes: 3

Related Questions