docker - Windows 10 Linux 子系统中的 Dockerfile 在当前目录中找不到文件
问题描述
我有Dockerfile
最后一行:
CMD ["./watch.sh"]
哪个只是运行npm run watch
. 在 Linux 中,一切正常。但是在 Windows 10 Subsytem for Linux (WSL) 中,docker 会抛出一个错误,说它找不到文件。在另一个Dockerfile
运行python <SOMEFILE.PY>
它还说它找不到文件。
我已经将这些设置在/etc/wsl.conf
:
[automount]
root = /
options = "metadata"
我在我的用户名进程中运行 docker,并且已经将我的名字放在了 docker 组中。所以,我不把它作为sudo
. 文件权限也在我的帐户中。
编辑:我只是意识到,似乎我需要将docker
客户端运行为sudo
. 在 Bash WSL 中,似乎找不到驻留在 Windows 中的 docker 引擎,通过 tcp://localhost:2375 访问
$ sudo usermod -aG docker root
$ sudo docker build -t build-minimal .
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
当我在没有 sudo 的情况下运行 docker 时,它可以工作。
解决方案
找到了!答案是文件权限。
我使用 WSL 的意图是拥有完全兼容的 Linux 环境,但仍然能够使用 Windows 工作。因此,Linux 和 Windows 之间的文件共享必须正确完成。
我以前的错误只是从 Linux 到我的 Windows 文件(即 Python Flask 应用程序)的符号链接。这很糟糕,因为文件权限将无法正确存储/读取。
解决方案:
- 指向代码/数据目录的符号链接位于 Windows 文件夹中
- 如果是 git 存储库,请
git clone
从 WSL 框中执行 - 这将使文件权限正确保留,您仍然可以从 WSL/Windows 中完美地访问它们
推荐阅读
- hadoop - namenode 中的问题,异常类型 javaBinding
- typescript - “EventTarget”类型上不存在属性“parentElement”
- azure - AADB2C90083:请求缺少必需参数:grant_type
- sql - Oracle 11:加入两个选择
- asp.net-mvc-4 - Visual Studio - 在 MVC 4 中找不到匹配的视图
- typescript - 如何取消 Selenium 中的特定等待?
- python - 删除重复项(python)
- python-3.x - 使用 subprocess.run 将文件从一种类型转换为另一种类型
- vuex - 使用 vuex-persistedstate 和 js-cookie 保存 Vuex 状态
- ubuntu - 是否可以在 linux 终端中使用 say-command 行?(不说话)