Git sh.exe & Docker run (no such file or directory)

Viewed 261

I have ran into a perplexing problem and cannot seem to find an explanation.

  1. Run /usr/bin/sh.exe (this is sh.exe provided by Git for Windows)

  2. Execute the following command: docker run alpine:edge /bin/sh -c "echo AAA"

  3. Observe error (for readability I am subbing git-installation-path): docker: Error response from daemon: OCI runtime create failed: container_linux.go:380: starting container process caused: exec: "<git-installation-path>/usr/bin/sh": stat <git-installation-path>/usr/bin/sh: no such file or directory: unknown.

I don't understand why dockeris trying to use a LOCAL path to sh.exe (the one from Git install)

The expected result is to run an Alpine container and execute the command /bin/sh -c "echo AAA" inside the container

1 Answers

In the version of bash used in Git for Windows, paths using / are rewritten into Windows paths. This is because many Windows programs don't handle Unix-style paths and this makes more programs work properly.

However, in your case, this results in /bin/sh being rewritten into the path to the Windows executable, which obviously you don't want if you're passing it into a Linux Docker container. The solution to this is to double the slashes (or at least the initial slash), which will tell the shell not to rewrite it.

Related