Mount current directory as a volume in Docker on Windows 10

后端 未结 10 970
滥情空心
滥情空心 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:41
    docker run --rm -v /c/Users/Christian/manager/bin:/app --workdir=/app  php:7.2-cli php  app.php
    

    Git bash

     cd /c/Users/Christian/manager
        docker run --rm -v  ${PWD}:/app  --workdir=/app  php:7.2-cli php  bin/app.php
    

    echo ${PWD} result:

    /c/Users/Christian/manager

    cmd or PowerShell

      cd C:\Users\Christian\manager
    

    echo ${PWD} result:

    Path ---- C:\Users\Christian\manager

    as we see in cmd or PowerShell $ {PWD} will not work

    0 讨论(0)
  • 2020-11-28 01:42
    1. Open Settings on Docker Desktop (Docker for Windows).
    2. Select Shared Drives.
    3. Select the drive that you want to use inside your containers (e.g., C).
    4. Click Apply. You may be asked to provide user credentials.

    5. The command below should now work on PowerShell (command prompt does not support ${PWD}):

      docker run --rm -v ${PWD}:/data alpine ls /data

    IMPORTANT: if/when you change your Windows domain password, the mount will stop working silently, that is, -v will work but the container will not see your host folders and files. Solution: go back to Settings, uncheck the shared drives, Apply, check them again, Apply, and enter the new password when prompted.

    0 讨论(0)
  • 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
    
    0 讨论(0)
  • This command should fix it.

    docker run --rm -it -v ${PWD}:c:\data mirkohaaser/docker-clitools

    {PWD} is the host current folder. after the : is the container folder. If the mounting is correct then files will be listed in the director c:\data in the container.

    0 讨论(0)
提交回复
热议问题