如何在 docker for windows 中访问主机中的卷 [英] How to access the volume in host in docker for windows
问题描述
我在 WSL 中运行适用于 Windows 和 ubuntu 的 docker.当我运行以下命令时
docker volume 创建测试
docker volume inspect test
我得到以下输出
<预><代码>[{驱动程序":本地",标签":{},挂载点":/var/lib/docker/volumes/test/_data",名称":测试",选项":{},范围":本地"}]当我访问该位置时,我得到bash: cd:/var/lib/docker/volumes: 没有那个文件或目录
那么我应该如何访问该文件夹?
该目录是受保护的,因此您可以 cd
进入其中,但是您可以 ls
的内容:
sudo ls/wsl/docker-desktop-data/data/docker/volumes/test/_data
我已经按照 这篇文章 所以你可能会发现你的路径是不同的.我认为默认路径可能是 /mnt/wsl/docker-desktop-data/data/docker/volumes/test/_data
您可能会发现在 Windows 用户文件夹中挂载一个目录更有用,这可以通过按照上面链接的文章更改 WSL 挂载点然后运行来完成:
docker volume create --driver local --name test --opt device=/run/desktop/mnt/host/c/Users//test --opt type=none --opto=绑定
(假设您在 Windows 用户目录的根目录中有一个名为 test
的文件夹)
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?
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)
这篇关于如何在 docker for windows 中访问主机中的卷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!