microsoft / Docker-PowerShell

PowerShell Module for Docker
MIT License
289 stars 87 forks source link

Mounted folder appears empty using Docker-PowerShell; fine with 'docker' #178

Open festus1973 opened 7 years ago

festus1973 commented 7 years ago

The following command executes successfully and I'm able to view my host directory "C:\temp" as "C:\scripts" on the container:

docker run -it -d --name festus -v c:\temp:c:\scripts core_usr_img

...but when performing the same action using the PowerShell module as follows...

$config = [Docker.DotNet.Models.Config]::new();
$config.Hostname="festus";
$dict = new-object 'system.collections.generic.dictionary[string,object]';
$dict.Add("C:\temp:c:\scripts",$null);
$config.Volumes = $dict;
$config;
Run-ContainerImage "core_usr_img" -Configuration $config -name "festus" -Detach -input

...the container starts up, 'scripts' appears as a folder in c:\, but it's empty. The container can't see the contents of the folder. Again, this works just fine using the raw 'docker' call. Only when using the PowerShell module does this bug occur. Any ideas?

festus1973 commented 7 years ago

Just a follow-up on this in case anyone else encounters the same thing. Mounting a host directory actually calls for use of the HostConfig class, not Config as indicated in some of the other forum posts here. Further, it's the 'Bind' property, not 'Volumes' that should be used to construct the mount. The follow revised script works and the directory is now visible from the container:

$config = [Docker.DotNet.Models.HostConfig]::new();
$config.Binds= new-object 'system.collections.generic.list[string]';
$config.Binds.Add("c:\temp:c:\scripts");
Run-ContainerImage "core_usr_img" -name "festus" -Detach -input -HostConfiguration $config