从 linux 样式路径转换时,Docker 安装的卷将 ;C 添加到 windows 路径的末尾 [英] Docker mounted volume adds ;C to end of windows path when translating from linux style path

查看:10
本文介绍了从 linux 样式路径转换时,Docker 安装的卷将 ;C 添加到 windows 路径的末尾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试在 Windows 上安装 docker 映像时发现了一些有趣的奇怪之处.

I've found some interesting weirdness when trying to mount a docker image on windows.

我创建了一个 .sh 脚本,它会挂载项目文件夹以运行我们的开发人员环境映像.我想要一个每个开发人员都可以运行的脚本,无论他们的机器如何.它所做的就是使用当前项目文件夹运行 docker.

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:myprojectfolder:/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 FilesDockerDockerResourcesindocker.exe: Error response from 
daemon: Mount denied:
The source path "D:/my/project/folder;C"
doesn't exist and is not known to Docker.

哇.;C 是什么?它从何而来?

Wat. What's ;C and where did it come from?

所以我做了 echo $PWD 这给了我 /d/my/project/folder.

So I do echo $PWD which gives me /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/9210https://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:MinGWmsys1.0x.注意其中的 ;C.如果 git-bash 想聪明一点,把语法塞满,然后用这种格式输出路径,这就可以解释了.

One of which outputs in the format: x;x;C:MinGWmsys1.0x. 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.

解决方案是转义路径转换,使用/作为前缀.因此,使用当前工作目录从 git-bash 运行 docker 的工作 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 安装的卷将 ;C 添加到 windows 路径的末尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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