gpt4 book ai didi

docker - 停止的 Docker 容器的资源使用情况

转载 作者:IT老高 更新时间:2023-10-28 12:40:16 32 4
gpt4 key购买 nike

Docker 可以轻松停止和重新启动容器。它还具有暂停然后取消暂停容器的能力。 Docker 文档状态

When the container is exited, the state of the file system and its exit value is preserved. You can start, stop, and restart a container. The processes restart from scratch (their memory state is not preserved in a container), but the file system is just as it was when the container was stopped.

我通过设置一个运行 memcached 的容器来测试这一点,然后将一个值写入 memcache,然后

  • 停止然后重新启动容器 - memcached 值消失了
  • 暂停然后取消暂停容器 - memcached 值仍然完好无损

在文档的某个地方 - 我再也找不到准确的文档 - 我读到停止的容器不会消耗 CPU 或内存。然而:

  • 我想保留文件系统状态这一事实意味着容器仍然会占用主机文件系统上的一些空间?
  • 系统中有 10 个甚至 100 个停止的容器是否会影响性能(主机磁盘空间消耗除外)?例如,Docker 是否更难启动和管理新容器?
  • 最后,如果 Paused 容器在 Unpaused 时保留其内存状态(如它们内存 memcached 键的能力所证明的那样),它们对 CPU 和内存的影响是否不同?

我非常感谢任何能够澄清这些问题的人。

最佳答案

我不是 docker core 方面的专家,但我会尝试回答其中的一些问题。

  1. I suppose the fact that the file system state is preserved means that the container still does consume some space on the host's file system?

是的。 Docker 将所有容器和图像数据保存在 /var/lib/docker 中。保存容器和图像数据的默认方式是使用 aufs。每一层的数据保存在/var/lib/docker/aufs/diff下。创建新容器时,还会使用 is 文件夹创建一个新层,并将源图像层的更改存储在该文件夹中。

  1. Is there a performance hit (other than host disk space consumption) associated with having 10s, or even 100s, of stopped containers in the system? For instance, does it make it any harder for Docker to startup and manage new containers?

据我所知,它不应该受到任何性能影响。当您停止一个容器时,docker daemon 会向该容器的所有进程发送 SIGTERM 和 SIGKILL,如 docker CLI documentation 中所述。 :

Usage: docker stop [OPTIONS] CONTAINER [CONTAINER...]

Stop a running container by sending SIGTERM and then SIGKILL after a grace period

-t, --time=10 Number of seconds to wait for the container to stop before killing it. Default is 10 seconds.


3.And finally, if Paused containers retain their memory state when Unpaused - as demonstrated by their ability to remember memcached keys - do they have a different impact on CPU and memory?

正如@Usman 所说,docker 使用 cgroup freezer 实现暂停/取消暂停。如果我没记错的话,当你将一个进程放入冷冻机(或其 cgroup)时,你会阻止内核任务调度程序执行该进程的新任务(即:它停止进程),但你没有杀死它们,它们会继续消耗它们正在使用的内存(尽管内核可能会将该内存移动到交换或固态磁盘)。我认为暂停容器使用的 CPU 资源微不足道。有关这方面的更多信息,我会检查此功能的拉取请求,Docker issue #5948

关于docker - 停止的 Docker 容器的资源使用情况,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27799282/

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