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
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
Click Apply. You may be asked to provide user credentials.
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.
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
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.
/
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 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
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.