carpentries-incubator / docker-introduction

Reproducible Computational Environments using Containers
https://carpentries-incubator.github.io/docker-introduction/
Other
42 stars 48 forks source link

Git Bash problem with path when creating mount #187

Open K-C-Martin opened 2 years ago

K-C-Martin commented 2 years ago

Lesson: Advanced Containers Permalink: https://github.com/carpentries-incubator/docker-introduction/blob/0aed5fb0263e779cf807bd649fe6f9ce626d0407/_episodes/advanced-containers.md

I'm using Git Bash on Windows 10 Enterprise.

When I try to run the following (following the Advanced Containers lesson):

docker container run --mount type=bind,source=${PWD},target=/temp alpine-python python3 /temp/sum.py

... I get the following error:

python3: can't open file '//C:/Program Files/Git/temp/sum.py': [Errno 2] No such file or directory

Prepending a / as suggested in the Setup (/${PWD}) doesn't fix the problem, but running the following first does:

export MSYS_NO_PATHCONV=1

aturner-epcc commented 2 years ago

Thanks for this @K-C-Martin. The issue with git bash is already noted in the setup.md file and it also gives people a workaround:

Warning: Git Bash

If you are using Git Bash as your terminal on Windows then you should be aware that you may run into issues running some of the commands in this lesson as Git Bash will automatically re-write any paths you specify at the command line into Windows versions of the paths and this will confuse the Docker container you are trying to use. For example, if you enter the command:

docker run alpine cat /etc/os-release

Git Bash will change the /etc/os-release path to C:\etc\os-release\ before passing the command to the Docker container and the container will report an error. If you want to use Git Bash then you can request that this path translation does not take place by adding an extra / to the start of the path. i.e. the command would become:

docker run alpine cat //etc/os-release

This should suppress the path translation functionality in Git Bash.

We could add a callout with this information again in the lessons to remind people if you think this would be useful.

K-C-Martin commented 2 years ago

Hi @aturner-epcc - I did try adding an extra / to ${PWD}, but it didn't seem to work... I got the same error message.

K-C-Martin commented 2 years ago

See the following series of attempts:

kcmartin@bosbou504824 MINGW64 ~/Desktop/docker-intro/sum
$ docker container run --mount type=bind,source=${PWD},target=/temp alpine-python python3 /temp/sum.py
python3: can't open file '//C:/Program Files/Git/temp/sum.py': [Errno 2] No such file or directory

kcmartin@bosbou504824 MINGW64 ~/Desktop/docker-intro/sum
$ docker container run --mount type=bind,source=/${PWD},target=/temp alpine-python python3 /temp/sum.py
python3: can't open file '//C:/Program Files/Git/temp/sum.py': [Errno 2] No such file or directory

kcmartin@bosbou504824 MINGW64 ~/Desktop/docker-intro/sum
$ docker container run --mount type=bind,source="/${PWD}",target=/temp alpine-python python3 /temp/sum.py
python3: can't open file '//C:/Program Files/Git/temp/sum.py': [Errno 2] No such file or directory

kcmartin@bosbou504824 MINGW64 ~/Desktop/docker-intro/sum
$ export MSYS_NO_PATHCONV=1

kcmartin@bosbou504824 MINGW64 ~/Desktop/docker-intro/sum
$ docker container run --mount type=bind,source=${PWD},target=/temp alpine-python python3 /temp/sum.py
sum = 0
K-C-Martin commented 2 years ago

Ah - I'm pretty sure I tried prepending / to /temp/sum.py too, with the same results, but let me confirm that.

p.s. it may take me a while to run this check - I've managed to break the machine I had got Docker running on.

p.p.s. in the meantime, let me say 'thank you' for this material: really, really appreciated having such a clear, practical walkthrough.