从 /var/lib/docker/aufs/diff/ 中删除的文件

Files deleted from within /var/lib/docker/aufs/diff/

Docker docs状态:

Warning: Do not directly manipulate any files or directories within /var/lib/docker/. These files and directories are managed by Docker.

假设某人没有阅读该提示并从 /var/lib/docker/aufs/diff 中删除了一些文件以释放一些磁盘 space。这些文件不在 Docker 卷 中,也不是原始 Docker 图像 的一部分,但已经在 容器可写层 中创建。重新启动给定的容器可以释放磁盘 space 但是有任何已知的副作用吗?

下一次:从容器中删除此类文件或目录(通过 docker exec .. rm ..)是否会导致正确删除或它们仅被标记为已删除?文档目前没有描述这种特殊情况。

Restarting the given container frees up the disk space but are there any known side effects?

正如您在问题中所述,您不应该 "manipulate any files or directories within /var/lib/docker/",因为任何副作用都可能出现,并且没有任何文档对此进行追踪:它是内部的 Docker 可能会极大地改变其他 Docker 版本的管道,但不应暴露给最终用户,也不应对其进行调和。您可以查看 Docker 版本的 Docker 代码及其所有依赖项以了解发生了什么,但这并不实用:-)

are there any known side effects?

可能会有副作用——我坚持可能因为任何事情都可能发生,这取决于你的Docker版本和配置。即使它看起来可以正常工作,但有些东西可能会损坏。

众所周知的副作用是 Docker 安装损坏,它可能以各种方式出现:随机容器崩溃、数据丢失、无法解释的错误等。

  • 最好的情况,您只是丢弃了容器中的一些数据,以后一切都会正常工作。
  • 不太好的情况:您实际上在安装中破坏了某些东西并损坏了它,您最好完全重新安装 Docker。

Does removing that kind of files or directories from within the container (via docker exec .. rm ..) result in a proper removal or are they only marked as deleted?

删除容器中的文件并不总是会从系统中删除它,这取决于您使用的驱动器。 Doc 有一节是关于为所有这些文件编写文件的:

  • AUFS - 似乎暗示文件已被删除,AUFS 将从图像层复制文件并对其进行处理,然后应该删除副本

    When a file is deleted within a container, a whiteout file is created in the container layer. The version of the file in the image layer is not deleted [...] Subsequent writes to the same file operate against the copy of the file already copied up to the container.

  • BTRFS - 删除并 space 回收,文档很清楚:

    If a container creates a file and then deletes it, this operation is performed in the Btrfs filesystem itself and the space is reclaimed.

  • devicemapper - 可能不会被删除,具体取决于配置:

    if you are using direct-lvm, the blocks are freed. If you use loop-lvm, the blocks may not be freed

  • OverlayFS - 似乎暗示文件已删除,但图像文件保留

    When a file is deleted within a container, a whiteout file is created in the container (upperdir). The version of the file in the image layer (lowerdir) is not deleted

  • ZFS - 已删除:

    If you create and then delete a file or directory within the container’s writable layer, the blocks are reclaimed by the zpool.

  • VFS 正在使用上一层的副本并直接在代表该层的目录中工作,容器中的删除可能应该从主机上的相关目录中删除它

The documentation currently doesn't describe this special case.

是的,可能不会 ;)