简体   繁体   English

Docker容器内存使用情况

[英]Docker container memory usage

I have a Lamp Docker Image. 我有一个Lamp Docker Image。 I want to start 500 containers of this image, how many RAM i need? 我想启动这个图像的500个容器,我需要多少RAM? I have tracked memory usage of each new container and it nearly the same as any other container of its image. 我跟踪了每个新容器的内存使用情况,它与其映像的任何其他容器几乎相同。 So,if single container is using 200 MB, I can start 5 containers on Linux machine with 1 GB RAM. 因此,如果单个容器使用200 MB,我可以在具有1 GB RAM的Linux机器上启动5个容器。

My question is: 我的问题是:

Is docker container using same memory as, for example, same Virtual Machine Image? docker容器是否使用相同的内存,例如,相同的虚拟机映像? May be I am doing something wrong in docker configuration or docker files? 可能是我在docker配置或docker文件中做错了什么?

docker stats might give you the feedback you need. docker stats可能会为您提供所需的反馈。 https://docs.docker.com/engine/reference/commandline/stats/ https://docs.docker.com/engine/reference/commandline/stats/

I don't know the exact details of the docker internals, but the general idea is that Docker tries to reuse as much as it can. 我不知道docker内部的确切细节,但一般的想法是Docker尝试尽可能多地重用。 So if you start five identical containers, it should run much faster than a virtual machine, because docker should only have one instance of the base image and file system which all containers refer to. 因此,如果您启动五个相同的容器,它应该比虚拟机运行得快得多,因为docker应该只有一个基本映像实例和所有容器引用的文件系统。 Any changes to the file system of one container will be added as a layer on top, only marking the change. 对一个容器的文件系统的任何更改都将作为一个层添加到顶部,仅标记更改。 The underlying image will not be changed, so the five containers can still refer to the same single base image. 底层图像不会更改,因此五个容器仍然可以引用相同的单个基本图像。

The virtual machine however (i believe) will have a complete copy of the file system for each of the five instances, because it doesn't use a layered file system. 然而,虚拟机(我相信)将为五个实例中的每个实例提供文件系统的完整副本,因为它不使用分层文件系统。

So I'm not sure how you can determine exactly how much memory you need, but this should make the concept clearer to you. 所以我不确定你如何确定你需要多少内存,但这应该让你的概念更加清晰。 You could start one container to see the 'base memory' that will be needed for one and then each new container should only add a smaller constant amount of memory and that should give you a broad idea how much you need. 您可以启动一个容器来查看一个容器所需的“基本内存”,然后每个新容器应该只添加一个较小的恒定内存量,这应该可以让您大致了解您需要多少内存。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM