为什么 Docker 需要联合文件系统

Why does Docker need a Union File System

Docker 联合文件系统(如 AUFS)究竟做了什么来创建容器?如果 Docker 必须使用常规文件系统而不是联合文件系统,缺点是什么?

我正在寻找具体的技术 details/internals 而不是高级答案。

用于:

  • 避免每次 运行 将图像作为新容器时复制一整套文件
  • 将对容器文件系统的更改隔离在它自己的层中,允许同一容器从已知内容重新启动(因为当容器被移除时,具有更改的层将被关闭)

那个UnionFS:

implements a union mount for other file systems. It allows files and directories of separate file systems, known as branches, to be transparently overlaid, forming a single coherent file system.
Contents of directories which have the same path within the merged branches will be seen together in a single merged directory, within the new, virtual filesystem.

This allows a file system to appear as writable, but without actually allowing writes to change the file system, also known as copy-on-write

如果您没有 UnionFS,一个 200MB 的图像 运行 5 倍作为 5 个单独的容器将意味着 1GB 的磁盘 space。

在“How does a Docker image work?”查看更多信息。
有关更多技术细节,请参阅: