docker build command add 'C:/Program Files/Git' to the path passed as build argument when executed in MINGW bash on Windows

前端 未结 2 1230
说谎
说谎 2021-02-19 17:43

I have following Dockerfile:

FROM ubuntu:16.04

ARG path1=def_path1
RUN mkdir ${path1}

When I build this Dockerfile using following command:

相关标签:
2条回答
  • 2021-02-19 18:17

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

    0 讨论(0)
  • 2021-02-19 18:22

    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

    0 讨论(0)
提交回复
热议问题