Skip to content

Instantly share code, notes, and snippets.

@borekb
Last active September 23, 2025 19:19
Show Gist options
  • Select an option

  • Save borekb/cb1536a3685ca6fc0ad9a028e6a959e3 to your computer and use it in GitHub Desktop.

Select an option

Save borekb/cb1536a3685ca6fc0ad9a028e6a959e3 to your computer and use it in GitHub Desktop.
Docker and Git Bash / MSYS2 on Windows: path conversion workaround

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

Git Bash is an awesome shell that comes with Git for Windows but Docker and Docker Compose don't work well in it due to path conversions, see e.g. this issue. Same with MSYS2 shells.

To confirm that you have the problem, 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 example is volume mapping, e.g.:

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

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

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

#!/bin/bash

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.

Hope this helps.

@listba
Copy link

listba commented May 8, 2018

What extention did you use for your script? I tried using .SH and adding .SH to my PATHEXT, but it still prioritizes Docker.exe unless i type docker.sh

@borekb
Copy link
Author

borekb commented May 13, 2018

@listba Sorry, missed your comment. The proxy scripts have no extension:

image

@tramel-woodard
Copy link

Great Gist... just an aside... if the 'type' command only searches for executables, how did you get it to return your 'docker' file, given that it doesn't have a .bat or .exe extension? I tried several times to use 'type -a docker' and it only returns the actual Docker.exe I imagine because it saw the .exe extension.

@MirKml
Copy link

MirKml commented Nov 8, 2018

I give up such a workarounds, because mostly docker run for inner bash is affected, other docker commands works fine for me in msys2, even simple docker run without parameters. I'm using powershell console for running bash from docker image. Second option for linux containers which I use is native linux distro in VirtualBox and docker in this linux guest.
But these information are definitely worth, thanks.

@borekb
Copy link
Author

borekb commented Mar 9, 2019

👋 Please visit https://github.com/borekb/docker-path-workaround for an up-to-date version of this Gist. Full GitHub repo allows for comment notifications and pull requests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment