Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

msys2 and docker run specifying the command: looks for the command locally before running in docker

Tags:

docker

msys2

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?

like image 242
Robert Hickman Avatar asked Oct 26 '18 19:10

Robert Hickman


1 Answers

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

like image 62
Robert Avatar answered Oct 04 '22 10:10

Robert