daisy
daisy

Reputation: 23541

How do I bind a volume in Windows docker?

I'm running Windows 2019 Server with latest docker.

I need to start a windows container, and bind the current C: to Z: in the container, but this does not work:

docker run -v c:\:z:\ -it XXX cmd.exe

What's the correct syntax?

EDIT

Here's what I've tried

PS C:\Users\Administrator> docker run --mount 'type="bind",source="C:\",target="Z:\"' -it mcr.microsoft.com/windows/nanoserver:1809 cmd.exe
invalid argument "type=bind,source=C:\",target=Z:\"" for "--mount" flag: parse error on line 1, column 19: bare " in non-quoted-field
See 'docker run --help'.
PS C:\Users\Administrator> docker run --mount type=bind,source=C:\,target=Z:\ -it mcr.microsoft.com/windows/nanoserver:1809 cmd.exe
docker: Error response from daemon: hcsshim::CreateComputeSystem 9b4e6759c82a071453bf4449f18dbbb2bd90511651c146a6e561a45771e0548c: The parameter is incorrect.
PS C:\Users\Administrator>

Upvotes: 1

Views: 1707

Answers (2)

AgilePro
AgilePro

Reputation: 5598

I just got this to work:

docker run -p 80:80 -v //e/testdata/:/opt/testdata imagetag

On host windows: e:\testdata

mapped in container: /opt/testdata

To access e:\testdata one needs to put a double slash before the drive letter, and no colon there. I am mapping into a linux container so that is a normal unix style path. The software inside the container was able to read and write the windows files.

Upvotes: 1

Lucas Bazetto
Lucas Bazetto

Reputation: 647

Did you try with mount syntax?

using Powershell:

docker run --mount 'type="bind",source="C:\",target="Z:\"' myimage:latest

or

Without quotes:

docker run --mount type=bind,source=C:\,target=Z:\ myimage:latest

Upvotes: 1

Related Questions