如何从 WSL 容器中访问 \\wsl$\othercontainer\some\file? [英] How to access \\wsl$\othercontainer\some\file from within a WSL container?

查看:45
本文介绍了如何从 WSL 容器中访问 \\wsl$\othercontainer\some\file?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Windows 中,我可以从 \\wsl$ 下访问所有 WSL 容器的文件系统.

From Windows, I can access the file systems of all the WSL containers from under \\wsl$.

并且从 WSL 容器内部,我可以以 /mnt/c 的形式访问 windows C:\ 驱动器.

And from inside a WSL container, I can access the windows C:\ drive as /mnt/c.

但是如何从 WSL 容器内部访问另一个容器的驱动器?

But how can I access another container's drive from inside a WSL container?

我正在尝试从 WSL 容器内部访问 \\wsl$\othercontainer\some\file.

I'm trying to access \\wsl$\othercontainer\some\file from inside a WSL container.

wslpath 通常可以将 Windows 文件路径转换为可从 WSL 访问的路径:

wslpath can normally convert Windows file paths to paths accessible from WSL:

WSL2@~» wslpath 'C:\Windows\System32\drivers\etc\hosts'
/mnt/c/Windows/System32/drivers/etc/hosts

但它不适用于:

WSL2@~» wslpath '\\wsl$\othercontainer\some\file'
wslpath: \\wsl$\othercontainer\some\file

WSL2@~» echo $?
1

当然还有:

WSL2@~» ls -l '\\wsl$\othercontainer\some\file'
ls: cannot access '\\wsl$\othercontainer\some\file': No such file or directory

推荐答案

这个答案 提供了答案:

sudo mkdir /mnt/othercontainer
sudo mount -t drvfs '\\wsl$\othercontainer' /mnt/othercontainer
ls -l /mnt/othercontainer/some/file

注意:似乎不支持符号链接.当遇到一个时,我们会收到如下错误:

NOTE: It looks like symbolic links aren't supported. When one is encountered, we get an error like:

$ ls -l /mnt/othercontainer/bin

ls: cannot read symbolic link '/mnt/othercontainer/bin': Function not implemented
lrwxrwxrwx 1 root root 7 Apr 23  2020 /mnt/othercontainer/bin

这篇关于如何从 WSL 容器中访问 \\wsl$\othercontainer\some\file?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆