WSL 中 docker 挂接目录问题

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u013272009/article/details/81222689

问题

WSL 中如 C 盘被挂接到 /mnt/下,因此路径为:

/mnt/c

而 docker for windows 中, docker run -v 挂接目录需要真是路径:

/c

因此会造成 如下命令在 WSL中挂接失败:

docker run -v $PWD:/aaa ...(省略)...

解决

github上已经有 issues:

https://github.com/docker/for-win/issues/860

Insider build 17093 has introduced a way of mounting to a custom root directory.
[automount]
root = /host_mnt/
Using docker-ce 17.12.0-ce-win47 and the new wsl root, $(pwd -P) is now usable for -v mapping.

对应的官方文档:

https://blogs.msdn.microsoft.com/commandline/2018/02/07/automatically-configuring-wsl/

也就是修改 /etc/wsl.conf 文件:

[automount]
enabled = true
root = /
options = "metadata,umask=22,fmask=11"
mountFsTab = false

然而实际试了下,居然没有效果。

操作版本问题

反复看文档,才注意到:

Beginning with Insider Build 17093, we added a method for you to automatically configure certain functionality in WSL that will be applied every time you launch the subsystem. This includes automount options and network configuration.

开篇就提到 版本号 : 17093 开始 … 才有这个功能。

如何查看自己的版本号。

打开 设置 -> 系统 -> 关于

这里写图片描述

红框所示的数字就是当前系统版本号。

这里查找版本号的官方文档为:

https://docs.microsoft.com/zh-cn/windows/wsl/troubleshooting#check-your-build-number

在官方文档:
https://docs.microsoft.com/zh-cn/windows/wsl/install-win10
中被引用

以上

猜你喜欢

转载自blog.csdn.net/u013272009/article/details/81222689