25

I have following Dockerfile:

FROM ubuntu:16.04

ARG path1=def_path1
RUN mkdir ${path1}

When I build this Dockerfile using following command:

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

I get following error when I execute it in MINGW bash on Windows 10:

$ ./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

Building same Dockerfile in Windows Command Prompt or on Linux or Mac is ok. The problem is only in MINGW bash terminal on Windows because it adds 'C:/Program Files/Git' before the path that is passed as argument.

Is there a way to execute this in MINGW bash so it does not add the 'C:/Program Files/Git' prefix?

Thanks

Dragan Nikolic
  • 1,536
  • 3
  • 17
  • 24
  • if I pass path1=home/dragan instead of path1=/home/dragan it works fine even in MINGW bash, so that helps. I'd still like to hear opinion about this issue. – Dragan Nikolic Jan 24 '18 at 16:40

2 Answers2

35

This is actually a bug/limitation of Git for Windows as described in the Release Notes under Known issues:

If you specify command-line options starting with a slash, POSIX-to-Windows path conversion will kick in converting e.g. "/usr/bin/bash.exe" to "C:\Program Files\Git\usr\bin\bash.exe". When that is not desired -- e.g. "--upload-pack=/opt/git/bin/git-upload-pack" or "-L/regex/" -- you need to set the environment variable MSYS_NO_PATHCONV temporarily, like so:

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

Alternatively, you can double the first slash to avoid POSIX-to-Windows path conversion, e.g. "//usr/bin/bash.exe".

mat007
  • 905
  • 8
  • 16
3

Further to @mat007's answer:

This bash function solved the problem more permanently for docker, without enabling MSYS_NO_PATHCONV globally, which causes another world of pain.

.bashrc

# 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" "$@")
}

You may need to do the same for docker-compose

Bae
  • 7,516
  • 5
  • 36
  • 42