npm + wsl + docker 和卷挂载的解决方案是什么?

What solutions with npm + wsl + docker and volume mounts?

我想从事一个依赖 Docker 和 NPM 的网络项目(这实际上是一个 LAMP 服务器)。我在 WSL 运行 上 Docker 守护程序 运行 在 Windows 上。

这是我的约束条件:

显然我不能满足这两个要求。

例如,如果我在 Windows 文件系统上的文件夹上从 WSL 安装 npm,我会收到很多错误,例如:

npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',

或者,只是模块不起作用 webpack not found

如果我将我的项目移动到 WSL 端,Docker 无法将我的项目安装到我的目标容器上...

我可以使用什么替代方案?

使用 WSL 时,Docker for Windows 希望您提供的卷路径格式与此匹配:/c/Users/username/dev/myapp.

但是 WSL 使用 /mnt/c/Users/username/dev/myapp 格式。

您必须将 WSL 配置为挂载在 / 而不是 /mnt

创建和修改新的 WSL 配置文件:


    sudo nano /etc/wsl.conf

    # Now make it look like this and save the file when you're done:

    [automount]
    root = /
    options = "metadata"

We need to set root = / because this will make your drives mounted at /c or /e instead of /mnt/c or /mnt/e.

The options = "metadata" line is not necessary but it will fix folder and file permissions on WSL mounts so everything isn’t 777 all the time within the WSL mounts. I highly recommend you do this!

Once you make those changes, sign out and sign back in to Windows to ensure the changes take effect

来源: https://nickjanetakis.com/blog/setting-up-docker-for-windows-and-wsl-to-work-flawlessly