从linux样式路径转换时,Docker装入的卷在Windows路径的末尾添加; C [英] Docker mounted volume adds ;C to end of windows path when translating from linux style path
问题描述
尝试在Windows上安装docker映像时,我发现了一些有趣的怪异现象。
I've found some interesting weirdness when trying to mount a docker image on windows.
我创建了 .sh
脚本,用于装载项目文件夹以运行我们的开发人员环境映像。我希望每个开发人员都可以运行一个脚本,而不管他们的计算机如何。
I created a .sh
script that does a mount of the project folder to run our developer environment image. I want one script that every dev can run, regardless of their machine. All it does is runs docker with the current project folder.
#!/usr/bin/env bash
docker run -it --rm -v D:\my\project\folder:/wkDir $IMAGE_TAG yarn dev
运行正常。现在的计划是从 npm
调用此脚本,因此我希望相对于当前文件夹可以使用此脚本。让我们尝试另一个版本。
Runs okay. Now the plan is to call this script from npm
, so I'd like this to work relative to the current folder. Let's try another version.
docker run -it --rm -v $ PWD:/ wkDir $ IMAGE_TAG yarn dev
失败:
C:\Program Files\Docker\Docker\Resources\bin\docker.exe: Error response from
daemon: Mount denied:
The source path "D:/my/project/folder;C"
doesn't exist and is not known to Docker.
Wat。什么是; C
,它是从哪里来的?
Wat. What's ;C
and where did it come from?
所以我做 echo $ PWD
这给了我 / d / my / project / folder
。
有趣,所以 $ PWD
解析为linux路径格式的正确路径,似乎docker正在尝试将其转换为正确的Windows路径,除非存在此; C
似乎无处不在。而 \
是 /
...
Interesting, so $PWD
resolves to the correct path in linux path format, and it seems like docker is trying to translate from that to the correct windows path, except there's this ;C
that appears out of nowhere. And the \
are /
...
我在VSCode的终端git bash和powershell中得到了相同的结果。
I get the same result in VSCode's terminal git bash and powershell.
更新:我注意到在VSCode的powershell终端中运行 .sh
,会打开一个单独的 cmd.exe
控制台窗口,在git bash中运行脚本。因此,这可能是git bash问题。
Update: I noticed that running the .sh
in VSCode's powershell terminal, opens a separate cmd.exe
console window which seems to run the script in git bash. So this might be a git bash issue.
推荐答案
因此,通过一些额外的挖掘,我发现了这三个与git-bash相关的线程清理docker mount:
So with some extra digging I found these three threads, related to git-bash mucking up docker mount:
https://forums.docker.com/t/weird-error-under-git-bash-msys-solved/9210
https://github.com/moby/moby/issues/24029#issuecomment-250412919
当我查看mingw关于git-bash正在使用的路径转换的文档时,我发现此语法表:
http://www.mingw.org/wiki/Posix_path_conversion
When I look up mingw's documentation on the path conversion git-bash is using, I find this table of syntax: http://www.mingw.org/wiki/Posix_path_conversion
其中之一输出格式为: x; x; C:\MinGW\msys\1.0\x
。请注意其中的; C
。如果git-bash试图变得更聪明,则填充语法并以这种格式输出路径,这将对此进行解释。
One of which outputs in the format: x;x;C:\MinGW\msys\1.0\x
. Note the ;C
in it. If git-bash is trying to be clever, stuffing up the syntax and outputting a path with this format, this would explain it.
解决方案是避免路径转换,使用 /
作为前缀。因此,工作中的docker命令可以从git-bash中使用当前工作目录运行docker:
Solution is to escape the path conversion, using by prefixing with /
. So the working docker command to run docker from git-bash with present working directory:
docker run -it --rm -v /${PWD}:/wkDir $IMAGE_TAG yarn dev
这篇关于从linux样式路径转换时,Docker装入的卷在Windows路径的末尾添加; C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!