Docker container memory usage

2019-04-18 14:17发布

I have a Lamp Docker Image. I want to start 500 containers of this image, how many RAM i need? 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.

My question is:

Is docker container using same memory as, for example, same Virtual Machine Image? May be I am doing something wrong in docker configuration or docker files?

标签: docker
2条回答
做个烂人
2楼-- · 2019-04-18 14:42

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. 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. 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.

查看更多
冷血范
3楼-- · 2019-04-18 14:46

docker stats might give you the feedback you need. https://docs.docker.com/engine/reference/commandline/stats/

查看更多
登录 后发表回答