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

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

The contents of the docker proxy script is this:

#!/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.

@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