Skip to content

Instantly share code, notes, and snippets.

@borekb
Last active September 23, 2025 19:19
Show Gist options
  • Save borekb/cb1536a3685ca6fc0ad9a028e6a959e3 to your computer and use it in GitHub Desktop.
Save borekb/cb1536a3685ca6fc0ad9a028e6a959e3 to your computer and use it in GitHub Desktop.

Revisions

  1. borekb revised this gist Mar 9, 2019. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,7 @@
    👋 Moved to https://github.com/borekb/docker-path-workaround

    ---

    # Docker in Git Bash / MSYS2 on Windows: path conversion workaround

    > **UPDATE 07/2018**: I switched from Git Bash to MSYS2 recently which should be very similar, if not the same, but there some subtle differences which made me realize this is more tricky than I thought and that I don't 100% understand what is going on. If someone can help, please let me know in the comments.
  2. borekb revised this gist Jul 11, 2018. 1 changed file with 51 additions and 21 deletions.
    72 changes: 51 additions & 21 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,48 +1,78 @@
    # Docker in Git Bash / MSYS2 on Windows: path conversion workaround

    Git Bash is an awesome shell that comes with [Git for Windows](https://gitforwindows.org/) but Docker and Docker Compose don't work well in it due to path conversions, see e.g. [this issue](https://github.com/docker/toolbox/issues/673). Same with MSYS2 shells.
    > **UPDATE 07/2018**: I switched from Git Bash to MSYS2 recently which should be very similar, if not the same, but there some subtle differences which made me realize this is more tricky than I thought and that I don't 100% understand what is going on. If someone can help, please let me know in the comments.
    To confirm that you have the problem, run this:
    Invoking `docker` in MSYS2 shell or Git Bash typically fails with complains about paths, for example:

    ```
    $ docker run --rm -it ubuntu /bin/bash
    stat C:/Program Files/Git/usr/bin/bash: no such file or directory
    ```

    If you get this error, you're impacted:
    or

    ```
    stat C:/Program Files/Git/usr/bin/bash: no such file or directory
    docker run -v "$PWD":/var/www/html php:7-apache
    # (complains about C:/... path)
    ```

    Note how the Linux path is prepended with `C:/Program Files/Git` which is of course completely wrong from the container's point of view. Another common example is volume mapping, e.g.:
    Note how the Linux path is prepended with `C:/Program Files/Git` which obviously breaks some of the commands.

    This happens because MSYS2 shells (which includes Git Bash) translate Linux paths to Windows paths whenever a native Windows binary is called. This is generally a good thing, making it possible to run e.g. `notepad /c/some/file.txt` from Git Bash.

    But with Docker, you typically want Linux paths, or, actually, it depends. This simple example is already very tricky:

    ```
    docker run -v "$PWD":/var/www/html php:7-apache
    docker run --rm -it -v "$PWD":/tmp/mounted ubuntu /bin/bash
    ```

    This commonly fails as well.
    - There is volume mapping. Because Docker doesn't support relative paths here, `"$PWD"` or `` `pwd` `` needs to be used. This might resolve to something like `/c/some/path` which might get translated to `C:\\some\\path`. Now it depends whether `docker.exe` supports this or not (it seems it does on Windows).
    - The `-t` option might be problematic in mintty and other terminals, yielding an error like _"the input device is not a TTY. If you are using mintty, try prefixing the command with 'winpty'"_.
    - `/bin/bash` should definitely not be translated to `C:/Program Files/Git/usr/bin/bash`, that is plain wrong.

    The key to a solution is to set either the `MSYS_NO_PATHCONV` variable for Git Bash shell, or `MSYS2_ARG_CONV_EXCL` for MSYS shells.

    Create two small scripts, `docker` and `docker-compose` (no extension) in some location that has **higher-priority than Docker's path**. Docker is quite aggressive and puts itself very high in the list, the safest way is to become no. 1 **system path** (not user path) to beat it. Here is an example from my computer:
    As a base for the workaround, create a small `docker` script (no extension) somewhere in your PATH, and make sure this script is higher-priority than the path of `docker.exe`. Docker is quite aggressive and puts itself very high in the list, the safest way is to become no. 1 **system path** (not user path) to beat it. Here is an example from my computer:

    ![image](https://user-images.githubusercontent.com/101152/39303507-b980631a-4956-11e8-8374-5182385a15a1.png)

    The contents of the `docker` proxy script should look like this:
    Verify with this:

    ```
    $ type -a docker
    docker is /c/Users/Borek/OneDrive/Programs/cmder/bin/docker
    docker is /c/Program Files/Docker/Docker/Resources/bin/docker
    ```

    Your script must be first!

    Now, put this into your script:

    ```sh
    ```
    #!/bin/bash
    winpty "docker.exe" "$@"
    ```

    > ❗ Until https://github.com/Alexpux/MSYS2-packages/issues/411 is resolved, make sure you use winpty binaries from https://github.com/rprichard/winpty/releases, _not_ from `pacman -S winpty`.
    That should be it. Try running this:

    ```
    docker run --rm -it -v "$PWD":/tmp/mounted ubuntu /bin/bash
    ```

    Inside the container session, `ls /tmp/mounted` should list your local PWD directory.

    If that doesn't work, you can try either the `MSYS_NO_PATHCONV` or `MSYS2_ARG_CONV_EXCL` environment variables. For example, I used this in the past:

    if [[ -v MSYS2_PATH_TYPE ]]; then
    # !!! Until https://github.com/Alexpux/MSYS2-packages/issues/411 is resolved,
    # !!! make sure you use winpty binaries from https://github.com/rprichard/winpty/releases
    # !!! *not* from `pacman -S winpty`.
    (export MSYS2_ARG_CONV_EXCL="*"; winpty "docker.exe" "$@")
    else
    (export MSYS_NO_PATHCONV=1; "docker.exe" "$@")
    fi
    ```
    # Git Bash shell:
    (export MSYS_NO_PATHCONV=1; "docker.exe" "$@")
    # MSYS2 mingw64 shell:
    (export MSYS2_ARG_CONV_EXCL="*"; winpty "docker.exe" "$@")
    ```

    However, I no longer seem to need it. I don't fully understand why.

    Similarly for `docker-compose`.
    For `docker-compose`, do the same.

    Hope this helps.
  3. borekb revised this gist Jul 11, 2018. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    # Docker in Git Bash / MSYS2 on Windows: path conversion workaround

    Git Bash is an awesome shell that comes with [Git for Windows](https://gitforwindows.org/) but Docker and Docker Compose don't work well in it due to path conversions, see e.g. [this issue](https://github.com/docker/toolbox/issues/673). Same with MSYS2 shells.

    To confirm that you have the problem, run this:
  4. borekb revised this gist Jul 11, 2018. 1 changed file with 22 additions and 7 deletions.
    29 changes: 22 additions & 7 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,6 @@
    Git Bash is an awesome shell that comes with [Git for Windows](https://gitforwindows.org/) but Docker and Docker Compose don't work well in it due to path conversions, see e.g. [this issue](https://github.com/docker/toolbox/issues/673). To confirm that you have the problem, try to run this:
    Git Bash is an awesome shell that comes with [Git for Windows](https://gitforwindows.org/) but Docker and Docker Compose don't work well in it due to path conversions, see e.g. [this issue](https://github.com/docker/toolbox/issues/673). Same with MSYS2 shells.

    To confirm that you have the problem, run this:

    ```
    $ docker run --rm -it ubuntu /bin/bash
    @@ -10,22 +12,35 @@ If you get this error, you're impacted:
    stat C:/Program Files/Git/usr/bin/bash: no such file or directory
    ```

    Note how the Linux path is prepended with `C:/Program Files/Git` which is of course completely wrong from the container's point of view. Another common examples are volume mappings.
    Note how the Linux path is prepended with `C:/Program Files/Git` which is of course completely wrong from the container's point of view. Another common example is volume mapping, e.g.:

    ```
    docker run -v "$PWD":/var/www/html php:7-apache
    ```

    The key to a solution is the `MSYS_NO_PATHCONV` variable. Create two small scripts, `docker` and `docker-compose`, and put them in a location that has **higher-priority than Docker's path**. Actually, Docker puts itself very high in the list, you have to become no. 1 **system path** (not user PATH) to beat it. Here is an example from my computer:
    This commonly fails as well.

    The key to a solution is to set either the `MSYS_NO_PATHCONV` variable for Git Bash shell, or `MSYS2_ARG_CONV_EXCL` for MSYS shells.

    Create two small scripts, `docker` and `docker-compose` (no extension) in some location that has **higher-priority than Docker's path**. Docker is quite aggressive and puts itself very high in the list, the safest way is to become no. 1 **system path** (not user path) to beat it. Here is an example from my computer:

    ![image](https://user-images.githubusercontent.com/101152/39303507-b980631a-4956-11e8-8374-5182385a15a1.png)

    The contents of the `docker` proxy script is this:
    The contents of the `docker` proxy script should look like this:

    ```sh
    #!/bin/bash

    (export MSYS_NO_PATHCONV=1; "docker.exe" "$@")
    if [[ -v MSYS2_PATH_TYPE ]]; then
    # !!! Until https://github.com/Alexpux/MSYS2-packages/issues/411 is resolved,
    # !!! make sure you use winpty binaries from https://github.com/rprichard/winpty/releases
    # !!! *not* from `pacman -S winpty`.
    (export MSYS2_ARG_CONV_EXCL="*"; winpty "docker.exe" "$@")
    else
    (export MSYS_NO_PATHCONV=1; "docker.exe" "$@")
    fi
    ```

    Similarly for `docker-compose`.

    One final important note is that **you have to do this after every Docker update**: it will simply put itself back at the top.

    Hope this helps.
  5. borekb created this gist May 2, 2018.
    31 changes: 31 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    Git Bash is an awesome shell that comes with [Git for Windows](https://gitforwindows.org/) but Docker and Docker Compose don't work well in it due to path conversions, see e.g. [this issue](https://github.com/docker/toolbox/issues/673). To confirm that you have the problem, try to run this:

    ```
    $ docker run --rm -it ubuntu /bin/bash
    ```

    If you get this error, you're impacted:

    ```
    stat C:/Program Files/Git/usr/bin/bash: no such file or directory
    ```

    Note how the Linux path is prepended with `C:/Program Files/Git` which is of course completely wrong from the container's point of view. Another common examples are volume mappings.

    The key to a solution is the `MSYS_NO_PATHCONV` variable. Create two small scripts, `docker` and `docker-compose`, and put them in a location that has **higher-priority than Docker's path**. Actually, Docker puts itself very high in the list, you have to become no. 1 **system path** (not user PATH) to beat it. Here is an example from my computer:

    ![image](https://user-images.githubusercontent.com/101152/39303507-b980631a-4956-11e8-8374-5182385a15a1.png)

    The contents of the `docker` proxy script is this:

    ```sh
    #!/bin/bash

    (export MSYS_NO_PATHCONV=1; "docker.exe" "$@")
    ```

    Similarly for `docker-compose`.

    One final important note is that **you have to do this after every Docker update**: it will simply put itself back at the top.

    Hope this helps.