Docker mounted volume adds ;C to end of windows path when translating from linux style path

后端 未结 7 1660
后悔当初
后悔当初 2020-12-07 14:11

I\'ve found some interesting weirdness when trying to mount a docker image on windows.

I created a .sh script that does a mount of the project folder to

7条回答
  •  天涯浪人
    2020-12-07 14:32

    Mounting the current directory into a Docker container in Windows 10 from Git Bash (MinGW) may fail due to a POSIX path conversion. Any path starting with / is converted to a valid Windows path.

    touch test.txt
    docker run --rm -v $(pwd):/data busybox ls -la /data/test.txt
    # ls: C:/Git/data/test.txt: No such file or directory
    

    Escape the POSIX paths by prefixing with /

    To skip the path conversion, all POSIX paths have to be prefixed with the extra leading slash (/), including /$(pwd).

    touch test.txt
    docker run --rm -v /$(pwd):/data busybox ls -la //data/test.txt
    # -rwxr-xr-x    1 root     root             0 Jun 22 23:45 //data/test.txt
    

    In Git Bash the path //data/test.txt is not converted and in Linux shells // (leading double slash) is ignored and treated the same way as /.

    Disable the path conversion

    Disable the POSIX path conversion in Git Bash (MinGW) using MSYS_NO_PATHCONV environment variable.

    The path conversion can be disabled at the command level:

    touch test.txt
    MSYS_NO_PATHCONV=1 docker run --rm -v $(pwd):/data busybox ls -la /data/test.txt
    # -rwxr-xr-x    1 root     root             0 Jun 22 23:45 /data/test.txt
    

    The path conversion can be disabled at the shell (or system) level:

    export MSYS_NO_PATHCONV=1
    touch test.txt
    docker run --rm -v $(pwd):/data busybox ls -la /data/test.txt
    # -rwxr-xr-x    1 root     root             0 Jun 22 23:45 /data/test.txt
    

提交回复
热议问题