【发布时间】:2020-10-21 23:45:34
【问题描述】:
我正在尝试将卷映射从 linux 容器映射到我的本地 Windows 机器。
步骤如下:
- 已安装最新版本的 Docker desktop for windows (2.4.0.0),目前使用的是基于 WSL2 的引擎。
- 在 alpine 映像之上使用我自己的映像启动了一个容器。工作目录在 linux 容器中设置为“/app”。
- 一旦运行,就会在我的 linux 容器中的文件夹 (Reports) 下创建一个输出文件 (Report.html)。能够查看容器中的文件。
- 我想将输出文件保存到本地 Windows 机器中我的用户目录下名为“Output”的文件夹中。
以管理员模式在 Power Shell 中运行以下命令:
docker run -it -v ~/Output:/app/Reports <imagename>
问题: 输出文件 (Report.html) 不会被复制到本地机器的输出文件夹中。
注意: 我没有在 Docker 设置中看到选择文件共享驱动器的选项。
请指导我如何解决这个问题?
【问题讨论】:
-
Report.html 位置在哪里。我认为应该是
./Report.html(在当前目录之前添加点)。试试这个~/Output/Report.html:./Report.html -
/app 是我在容器中的工作目录。 Report.html 保存在应用程序中。我试过~/Output/Report.html:/app/Report.html。但它没有用。我还更改了代码以将 Report.html 保存在 /app 下的 Reports 文件夹中并尝试:~/Output:/app/Reports。它也没有复制。
-
./Report.html 被视为无效的路径挂载规范并引发错误。
标签: docker windows-subsystem-for-linux docker-volume wsl-2 mounted-volumes