【问题标题】:Docker Volume Mapping: File is not getting copied from Docker linux container to local windows machineDocker 卷映射:文件未从 Docker linux 容器复制到本地 Windows 机器
【发布时间】:2020-10-21 23:45:34
【问题描述】:

我正在尝试将卷映射从 linux 容器映射到我的本地 Windows 机器。

步骤如下:

  1. 已安装最新版本的 Docker desktop for windows (2.4.0.0),目前使用的是基于 WSL2 的引擎。
  2. 在 alpine 映像之上使用我自己的映像启动了一个容器。工作目录在 linux 容器中设置为“/app”。
  3. 一旦运行,就会在我的 linux 容器中的文件夹 (Reports) 下创建一个输出文件 (Report.html)。能够查看容器中的文件。
  4. 我想将输出文件保存到本地 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


【解决方案1】:

使用绝对路径代替~工作,即 docker run -v C:/Users/12345/Output:/app/Reports

【讨论】:

    猜你喜欢
    • 2020-09-11
    • 2022-01-27
    • 1970-01-01
    • 1970-01-01
    • 2014-03-29
    • 2019-05-15
    • 1970-01-01
    • 2022-08-17
    相关资源
    最近更新 更多