Docker mount issue
Just some interesting code to remember
The Issue
I use Git Bash
on Windows 10
and want to mount a folder of the host machine into a docker container.
This is not possible as docker claims the directory would not exist:
$> docker run --rm -v c:/Users:/data alpine ls /data
ls: C:/Program Files/Git/data: No such file or directory
Possible Solutions
Using the Powershell
Using the Powershell
instead of Git Bash
sems to work.
The Bug only happens only when using Docker
within Git Bash
.
For me this is not helpful as i need bash for development.
Prepend MSYS_NO_PATHCONV=1 to every docker call
It seems this Bug happens because of a double encoding of the windows path. If the path is only encoded once, docker can mount the folder.
$> MSYS_NO_PATHCONV=1 docker run --rm -v c:/Users:/data alpine ls /data
...
My Solution
Instead of prepend the docker command with 'MSYS_NO_PATHCONV=1' every time, i created two wrapper scripts:
Put the following into C:\PortableApps\commandhelper\docker (without file extension):
#!/bin/bash
echo "using wrapper"
(export MSYS_NO_PATHCONV=1; "docker.exe" "$@")
Put the following into C:\PortableApps\commandhelper\docker-compose (without file extension):
#!/bin/bash
echo "using wrapper"
(export MSYS_NO_PATHCONV=1; "docker-compose.exe" "$@")
Now add C:\PortableApps\commandhelper to the PATH Variable with a higher priority then the docker folder itself.
When this setting is active, we can now use docker directly from Git Bash
without mounting problems:
$> docker run --rm -v c:/Users:/data alpine ls /data
using wrapper
...
Read More
- https://github.com/docker/toolbox/issues/673
- https://gist.github.com/borekb/cb1536a3685ca6fc0ad9a028e6a959e3