How to mount a Windows' folder in Docker using Powershell (or CMD)?
This works in PowerShell:
docker run --rm -v ${PWD}:/data alpine ls /data
See Mount current directory as a volume in Docker on Windows 10.
As documented /<drive>/<path>
is the correct syntax for mounting folders:
On Windows, mount directories using:
docker run -v /c/Users/<path>:/<container path> ...
You can make your command more generic by transforming a path to what Docker expects:
$PWD.Path -replace '^|\\+','/' -replace ':'
like this:
docker run -v "$($PWD.Path -replace '^|\\+','/' -replace ':')":/data -- ...
If the drive letter must be lowercased (can't test, since I don't have Docker running on Windows) it gets a little more complicated. If you can lowercase the entire string you could replace $PWD.Path
with $PWD.Path.ToLower()
. If you must lowercase just the drive letter and preserve case in the rest of the path you could use a callback function:
$re = [regex]'^([A-Z]):'$cb = { $args[0].Groups[1].Value.ToLower() }docker run -v "$($re.Replace($PWD.Path, $cb) -replace '^|\\+','/')":/data -- ...