Mac环境,建议不要使用docker作为开发环境

技术分享 · Axin · 于 3年前 发布 · 4404 次阅读

参考文献

Mac版Docker中的用户引导缓存

Docker 优化之 Docker-sync 解决 Docker 挂载缓慢

环境说明

  • mac
  • macOS mojave 10.14.5
  • Docker Desktop
  • Docker version 19.03.13, build 4484c46d9d
  • docker-sync

原因说明

序言

使用mac的朋友,尽量别用docker做为开发环境,请求耗时非常慢,使用了docker-sync与cache皆无果,目前我已回退homestead+vagrant开发环境,有解决方法可以一起探讨一下。

详见:Mac版Docker中的用户引导缓存

Bind mounts on Docker for Mac The Linux kernel makes container-style isolation efficient, but running containers on Docker editions for non-Linux operating systems such as macOS involves several additional moving parts that carry additional overhead.

Docker containers run on top of a Linux kernel, and so the Docker for Mac container runtime system runs a minimal Linux instance using the HyperKit framework. Containers running on top of the Linux system cannot directly access macOS filesystem or networking resources, and so Docker for Mac includes libraries that expose those resources in a way that the Docker engine can consume.

Access to filesystem resources is provided by a separate non-privileged macOS process (osxfs) that communicates with a daemon (“transfused”) running on the virtualized Linux. A Linux system call such as open or read that accesses bind-mounted files in a container must be.

机翻如下

在Mac版Docker上绑定安装 Linux内核提高了容器样式的隔离效率,但是在非Linux操作系统(例如macOS)的Docker版本上运行容器 涉及多个额外的活动部件 ,这些部件带来了额外的开销。

Docker容器在Linux内核之上运行,因此Docker for Mac容器运行时系统使用HyperKit 框架运行最小的Linux实例。在Linux系统之上运行的容器无法直接访问macOS文件系统或网络资源,因此Docker for Mac包含以Docker引擎可以使用的方式公开这些资源的库。

对文件系统资源的访问由一个单独的非特权macOS进程(osxfs)提供,该进程与虚拟化Linux上运行的守护程序(“ transfused”)进行通信。open 或read 访问容器中绑定安装的文件的Linux系统调用必须为。

我理解就是:因容器访问macOS文件系统导致慢

解决方案

  1. docker-sync(比较麻烦,会间歇性死亡,弃之)

  2. :cached 提高读取速度(没有较大的改善)

  3. 使用本地开发环境或homestead+vagrant等方式重构开发环境(推荐)

本文由 Axin 创作,采用 知识共享署名 3.0 中国大陆许可协议 进行许可。 可自由转载、引用,但需署名作者且注明文章出处。 本文由 Axin 创作,采用 知识共享署名 3.0 中国大陆许可协议 进行许可。 可自由转载、引用,但需署名作者且注明文章出处。

共收到 0 条回复 技术分享
没有找到数据。
添加回复 (需要登录)
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册
Your Site Analytics