1

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

1 Answer 1

3

I set $MyPath to C:\\Users\\Me, manually set $Opts, then ran the container as your script did, and got it to fail in the same exact way. Perfect.

Changing your command from

docker run --rm ${Opts} alpine:3.12

to

Invoke-Expression -Command "docker run --rm ${Opts} alpine:3.12"

didn't fail. Not sure what this should have done other than crank up an instance of Alpine and share a local path to the container, but it might be worth trying?

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, it doesn't do anything more than this. But it is just a small aspect of a larger script and was intended to be a minimal (not) working example. Thanks to you it is now a working(!) example. Cheers

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.