10

Within msys2, anytime I try to execute a docker run [image] [cmd] command such that I'm trying to run in the docker container overwrites the command specified in the Dockerfile, it looks for the command locally and fails if it doesn't exist.

For example, my organization has a docker image where the python executable is at /usr/src/venv/bin/python and python is not in $PATH. That is not where my local python is installed and when I try to run docker run myimage /usr/src/venv/bin/python test.py I get this error: OCI runtime create failed: container_linux.go:348: starting container process caused "exec: \"C:/msys64/usr/src/venv/bin/python\": stat C:/msys64/usr/src/venv/bin/python: no such file or directory" This image is not a windows image and so it shouldn't be looking at C: at all so I must conclude it's looking for that command locally instead of within the container.

Note: The docker I'm running is Docker for windows added to my $PATH within msys2.

$ which docker
/c/Program Files/Docker/Docker/Resources/bin/docker.exe

One workaround I've used is to create a new Dockerfile that just has a line to say to use the image I want and another that is the command I want. Then I can run docker run some-image without specifying a command and it works.

Is there some way I can fix this problem within msys2 without the annoying workaround described above?

Robert Hickman
  • 997
  • 1
  • 11
  • 22
  • Just to troubleshoot, try: `docker run --entrypoint=/usr/src/venv/bin/python myimage test.py` – Robert Nov 27 '18 at 20:20
  • Out of curiosity did you try it with `myvolume:/`. So in your case it would be `docker run myvolume:/ myimage /usr/src/venv/bin/python test.py` – tukan Nov 28 '18 at 08:45
  • @Robert, sorry for the delay. I tried that and got the same error – Robert Hickman Dec 11 '18 at 20:16
  • @tukan, I'm not sure exactly what you're suggesting. That doesn't seem to be a valid format for a docker command at all. – Robert Hickman Dec 11 '18 at 20:20
  • Brute force: `docker run myimage sh` (or bash), then `find / -name python` – Robert Dec 11 '18 at 20:25
  • @Robert, the problem isn't that I can't run docker commands, it's that on my team we have shell scripts to automatically run sets of commands and because of this weird behavior in msys2+docker-for-windows, those scripts don't work for me out of the box. I'm perfectly capable of making it work, but it seems like such non-standard docker behavior. Running the same docker command mentioned above in powershell works. Powershell isn't a great option because the shell scripts expect a bash-like environment. – Robert Hickman Dec 11 '18 at 20:35
  • 1
    Is it working with double slash? `docker run myimage //usr/src/venv/bin/python test.py` – Robert Dec 11 '18 at 23:07
  • 1
    Yes! That totally did it. Thanks so much – Robert Hickman Dec 11 '18 at 23:21

1 Answers1

3

This is due to MinGW Posix Path Convertion.

I found two work arounds.

Use double-slash // to start the path, then MSYS won't translate the path:

docker run myimage //usr/src/venv/bin/python test.py
                   ^^this

Another way is to suppress the path translation by setting MSYS_NO_PATHCONV=1 in Windows Git MSys or MSYS2_ARG_CONV_EXCL="*" in MSYS2.

Sources:

How to stop mingw and msys from mangling path names given at the command line?

https://github.com/git-for-windows/git/issues/577#issuecomment-166118846

Robert
  • 33,429
  • 8
  • 90
  • 94