I'm trying to bind mount a hostpath to a Docker container using a Powershell script as wrapper for my docker run call using Docker Desktop WSL2.
The problem seems to be, that I store the bind mount option in the $Opts variable. I need this to only use specific options to the docker run command depending on params passed to the script.
Minimal (not) Working Example:
param (
[String] $MyPath = ""
)
begin {
$Opts = "-v ${MyPath}:/etc/dir:ro "
docker run --rm ${Opts} alpine:3.12
}
Call:
.\test.ps1 ${HOME}
Error:
docker: Error response from daemon: Mount denied:
The source path " C:\\Users\\knoppiks:/etc/dir:ro "
too many colons.
See 'docker run --help'.
If I use the bind-mount option directly without storing it in a variable it works.
docker run --rm -v ${MyPath}:/etc/dir:ro alpine:3.12