docker build命令添加' C:/ Program Files / Git'在Windows上的MINGW bash中执行时作为构建参数传递的路径

时间:2018-01-24 16:32:59

标签: windows bash docker mingw

我有以下Dockerfile:

FROM ubuntu:16.04

ARG path1=def_path1
RUN mkdir ${path1}

使用以下命令构建此Dockerfile时:

docker build --build-arg path1=/home/dragan -t build_arg_ex .

我在Windows 10上的MINGW bash中执行它时出现以下错误:

$ ./build.sh --no-cache
Sending build context to Docker daemon  6.144kB
Step 1/3 : FROM ubuntu:16.04
 ---> 2a4cca5ac898
Step 2/3 : ARG path1=def_path1
 ---> Running in a35241ebdef3
Removing intermediate container a35241ebdef3
 ---> 01475e50af4c
Step 3/3 : RUN mkdir ${path1}
 ---> Running in 2759e683cbb1
mkdir: cannot create directory 'C:/Program': No such file or directory
mkdir: cannot create directory 'Files/Git/home/dragan': No such file or 
directory
The command '/bin/sh -c mkdir ${path1}' returned a non-zero code: 1

在Windows命令提示符或Linux或Mac上构建相同的Dockerfile是可以的。问题出在Windows上的MINGW bash终端中,因为它添加了C:/ Program Files / Git'在作为参数传递的路径之前。

有没有办法在MINGW bash中执行它,所以它不会添加' C:/ Program Files / Git'前缀?

由于

2 个答案:

答案 0 :(得分:5)

这实际上是Git for Windows的错误/限制,如Release Notes under Known issues

中所述
  

如果指定以斜杠开头的命令行选项,POSIX到Windows的路径转换将启用转换,例如“/usr/bin/bash.exe”改为“C:\ Program Files \ Git \ usr \ bin \ bash.exe”。当不需要时 - 例如“--upload-pack = / opt / git / bin / git-upload-pack”或“-L / regex /” - 您需要临时设置环境变量MSYS_NO_PATHCONV,如下所示:

MSYS_NO_PATHCONV=1 git blame -L/pathconv/ msys2_path_conv.cc
     

或者,您可以将第一个斜杠加倍以避免POSIX到Windows路径转换,例如“//usr/bin/bash.exe”。

答案 1 :(得分:0)

进一步了解enter image description here

此bash函数为docker更永久地解决了该问题,而没有全局启用this.stripe = await loadStripe(MY-CREDENTIAL); console.log("stripe",this.stripe) this.session = await this.stripe.checkout.sessions.retrieve(ID); ,这引起了另一番痛苦。

.bashrc

MSYS_NO_PATHCONV

您可能需要对# See https://github.com/docker/toolbox/issues/673#issuecomment-355275054 # Workaround for Docker for Windows in Git Bash. docker() { (export MSYS_NO_PATHCONV=1; "docker.exe" "$@") }

做同样的事情