在 Docker 中安装文件夹:Windows 主机,Windows 图像

Mounting Folders in Docker: Windows Host, Windows Image

如何使用docker挂载选项在Docker容器中共享本地文件夹?目前,我正在使用这个命令,但我没有成功。

docker run --mount source='c:\temp',target='c:\temp' -i newname:latest

我收到这个错误 -

C:\Program Files\Docker\docker.exe: Error response from daemon: invalid mount config for type "volume": invalid volume name.

我的环境: 主机:Windows 服务器,版本 1709 Docker 容器:Windows 服务器核心,v1709

您需要使用bind挂载。下面的示例将您的 host 目录 c:\users\public\ 映射到容器 c:\users\public 中的目录,然后输出该目录的内容。

PS C:\Users\gsuvalia> docker run --rm --mount type=bind,source=c:\users\public\,destination=c:\users\public\ microsoft/nanoserver powershell get-childitem c:\users\public


    Directory: C:\users\public


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-r---        12/1/2017  10:16 PM                Documents
d-r---        7/16/2016   6:47 AM                Downloads
d-r---        7/16/2016   6:47 AM                Music
d-r---        12/1/2017  10:16 PM                Pictures
d-----        8/22/2017  10:26 PM                Roaming
d-r---        7/16/2016   6:47 AM                Videos