Mount current directory as a volume in Docker on Windows 10

后端 未结 10 1027
滥情空心
滥情空心 2020-11-28 01:22

Description

I am using Docker version 1.12.5 on Windows 10 via Hyper-V and want to use container executables as commands in the current path. I buil

10条回答
  •  野性不改
    2020-11-28 01:50

    Command prompt (Cmd.exe)

    When the Docker CLI is used from the Windows Cmd.exe, use %cd% to mount the current directory:

    echo test > test.txt
    docker run --rm -v %cd%:/data busybox ls -ls /data/test.txt
    

    Git Bash (MinGW)

    When the Docker CLI is used from the Git Bash (MinGW), mounting the current directory may fail due to a POSIX path conversion: Docker mounted volume adds ;C to end of windows path when translating from linux style path.

    Escape the POSIX paths by prefixing with /

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

    touch test.txt
    docker run --rm -v /$(pwd):/data busybox ls -la //data/test.txt
    

    Disable the path conversion

    Disable the POSIX path conversion in Git Bash (MinGW) by setting MSYS_NO_PATHCONV=1 environment variable at the command level

    touch test.txt
    MSYS_NO_PATHCONV=1 docker run --rm -v $(pwd):/data busybox ls -la /data/test.txt
    

    or shell (system) level

    export MSYS_NO_PATHCONV=1
    touch test.txt
    docker run --rm -v $(pwd):/data busybox ls -la /data/test.txt
    

提交回复
热议问题