gpt4 book ai didi

Docker 桌面 - 关于性能不佳的文件共享通知

转载 作者:行者123 更新时间:2023-12-04 04:27:00 35 4
gpt4 key购买 nike

当我的 Docker 容器启动时,我收到以下通知:

Docker Desktop has detected that you shared a Windows file into a WSL 2 container, which may perform poorly. Click here for more details.


enter image description here
我的问题是:
  • 这是什么意思?
  • 什么是更好的做法/如何避免这种情况?
  • 如果消息已关闭,或者我点击了“不再显示”,我如何才能获得此警告的详细信息?

  • 如果需要,我很乐意分享 Dockerfile 或 Docker-Compose 设置,但我根本无法在 SO 上或通过谷歌搜索找到任何指向任何方向的东西,所以我不知道从哪里开始。我假设问题出在 Dockerfile 中,因为这是我们运行 COPY 的地方。移动一些文件。
    Docker 版本 : Docker 桌面 2.4.0.0 (48506) 社区
    操作系统 :Windows 10 专业版(版本 10.0.19041)

    最佳答案

  • 这个错误意味着从 Linux 容器访问 Windows 主机文件系统上的文件将比访问已经在 Linux 文件系统中的文件慢一点。从 Linux 容器访问 Windows 文件与访问远程文件共享上的文件一样。
  • Docker 和 Microsoft 建议通过将源文件存储在 WSL2 发行版的文件系统中(您可以将挂载绑定(bind)到容器)或构建容器镜像以包含所有需要的文件而不是将文件存储在 Windows 文件系统中来避免这种情况。
  • 如果您点击了“不再显示”,您可以前往 Develop with Docker and WSL 2 获取此消息的详细信息。 .

  • 欲了解更多信息, Docker for Windows Best Practices说:
    • Linux containers only receive file change events (“inotify events”) if the original files are stored in the Linux filesystem. For example, some web development workflows rely on inotify events for automatic reloading when files have changed.
    • Performance is much higher when files are bind-mounted from the Linux filesystem, rather than remoted from the Windows host. Therefore avoid docker run -v /mnt/c/users:/users (where /mnt/c is mounted from Windows).
    • Instead, from a Linux shell use a command like docker run -v ~/my-project:/sources <my-image> where ~ is expanded by the Linux shell to $HOME.

    微软 Comparing WSL 1 and WSL 2文章有一个完整的部分 Performance across OS file systems ,它的开头段落说:

    We recommend against working across operating systems with your files, unless you have a specific reason for doing so. For the fastest performance speed, store your files in the WSL file system if you are working in a Linux command line (Ubuntu, OpenSUSE, etc). If you're working in a Windows command line (PowerShell, Command Prompt), store your files in the Windows file system.


    此外,Docker 博客文章 Docker Desktop: WSL 2 Best practices有一个“很棒的坐骑性能”部分,上面写着:

    Both your own WSL 2 distro and docker-desktop run on the same utility VM. They share the same Kernel, VFS cache etc. They just run in separate namespaces so that they have the illusion of running totally independently. Docker Desktop leverages that to handle bind mounts from a WSL 2 distro without involving any remote file sharing system. This means that when you mount your project files in a container (with docker run -v ~/my-project:/sources <...>), docker will propagate inotify events and share the same cache as your own distro to avoid reading file content from disk repeatedly.

    A little warning though: if you mount files that live in the Windows file system (such as with docker run -v /mnt/c/Users/Simon/windows-project:/sources <...>), you won’t get those performance benefits, as /mnt/c is actually a mountpoint exposing Windows files through a Plan9 file share.


    如果您希望您的主要开发工作流程在 Linux 中,那么所有这些建议都很棒。 Docker 希望你在 Linux 容器上“全力以赴”。但是,如果您主要在 Windows 中工作并且只想使用 Linux 容器来执行专门的任务,那么单击“不再显示”就可以了。正如微软所说,“如果您在 Windows 命令行中工作,请将您的文件存储在 Windows 文件系统中。”
    我在 Windows 中使用我的主开发文件夹运行,并将它绑定(bind)到仅用于执行单元测试的 Linux 容器。所以我的完整构建在 Windows 中运行,然后我在 Windows 中运行所有单元测试,最后我也在 Linux 容器中运行所有单元测试。让 Linux 绑定(bind)挂载到我的 Windows 文件夹非常适合这种情况,因为 Linux 中的“dotnet 测试”调用只是从我的 Windows 卷中加载和执行所需的 DLL。
    对于那些认为必须在任何地方使用容器的人来说,这种设置听起来像是异端,但我喜欢容器用于应用程序部署。我不相信您也需要全力以赴并在容器内进行所有开发。我对 Windows(和 VS 2019)作为我的开发环境感到满意,然后我使用 Linux 容器进行应用程序测试和部署。因此,Windows/WSL2 文件系统性能对我的影响很小。

    关于Docker 桌面 - 关于性能不佳的文件共享通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64484579/

    35 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com