28

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

1
  • 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. Jan 24, 2018 at 16:40

2 Answers 2

39

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".

1
  • 2
    Thank you! Escaping the initial slash means I can run docker exec from gitbash :)
    – majjam
    Jun 11, 2021 at 11:04
4

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

1
  • Works perfectly, thanks! Nov 9 at 11:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.