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

后端 未结 7 1638
后悔当初
后悔当初 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
    
    0 讨论(0)
  • 2020-12-07 14:32

    I've actually had the same issue. Depending on if you are using Git Bash this command works(using nginx as an example):

    docker container run --name container-name -v `pwd -W` /html:/usr/share/nginx/html -p 8000:80 -d nginx

    of course you can specify the port and directory as you desire.

    0 讨论(0)
  • 2020-12-07 14:39

    Can you try below command -

    docker run -it --rm -v %cd%:/wkDir $IMAGE_TAG yarn dev
    
    0 讨论(0)
  • 2020-12-07 14:42

    So with some extra digging I found these three threads, related to git-bash mucking up docker mount:

    https://forums.docker.com/t/weird-error-under-git-bash-msys-solved/9210 https://github.com/moby/moby/issues/24029#issuecomment-250412919

    When I look up mingw's documentation on the path conversion git-bash is using, I find this table of syntax: http://www.mingw.org/wiki/Posix_path_conversion

    One of which outputs in the format: x;x;C:\MinGW\msys\1.0\x. Note the ;C in it. If git-bash is trying to be clever, stuffing up the syntax and outputting a path with this format, this would explain it.

    Solution is to escape the path conversion, using by prefixing with /. So the working docker command to run docker from git-bash with present working directory:

    docker run -it --rm -v /${PWD}:/wkDir $IMAGE_TAG yarn dev
    
    0 讨论(0)
  • 2020-12-07 14:52

    For me the solution was simply to include a closing slash / at end of any paths.

    E.g. instead of

    /opt/apache-atlas-2.0.0/bin/atlas_start.py

    ...use

    /opt/apache-atlas-2.0.0/bin/atlas_start.py/

    0 讨论(0)
  • 2020-12-07 14:55

    Straight worked for me below. just don't use dynamic variable.

    docker run --rm -u root -p 8080:8080 -v jenkins-data/:/var/jenkins_home -v /var/run/docker.sock/:/var/run/docker.sock -v /Users/<YOUR USER NAME>/:/home jenkinsci/blueocean
    
    0 讨论(0)
提交回复
热议问题