Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

docker exec –workdir does not work in git-bash

I’m running Docker Desktop 4.19.0 under Windows 10.

There is a container running and I can exec a command on it with docker exec from git-bash, cmd and Ubuntu-on-WSL2.

#git-bash
me@machine MINGW64 ~
$ docker exec 3eef5ce3f69d pwd
/

#cmd
C:\Users\me>docker exec 3eef5ce3f69d pwd
/

#ubuntu
frank@machine:~$ docker exec 3eef5ce3f69d pwd
/

so far, so good. The problem arises when I want to change the WORKDIR.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

While that works on cmd and ubuntu, it fails when run from git-bash. But why?

#git-bash
me@machine MINGW64 ~
$ docker exec --workdir=/tmp 3eef5ce3f69d pwd
OCI runtime exec failed: exec failed: Cwd must be an absolute path: unknown

#cmd
C:\Users\me>docker exec --workdir=/tmp 3eef5ce3f69d pwd
/tmp

#ubuntu
frank@machine:~$ docker exec --workdir=/tmp 3eef5ce3f69d pwd
/tmp

>Solution :

Git bash does some non-standard stuff with path expansion to make things like /bin/sh map back to the Git bash installation directory. To disable that behavior, use a leading double slash (//path/to/file):

docker exec --workdir=//tmp 3eef5ce3f69d pwd
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading