What is the impact of using multiple Base Images in Docker?

放肆的年华 提交于 2019-12-18 10:49:32

问题


I understand that docker containers are portable between docker hosts, but I am confused about the relationship with the Base Image and the host.

From the documentation on Images, it appears that you would have a much heavier footprint (akin to multiple VMs) on the host machine if you had a variety of base images running. Is this assumption correct?

  • GOOD: Many containers sharing a single base image.
  • BAD: Many containers running separate/unique base images.

I'm sure a lot of this confusion comes from my lack of knowledge of LXC.


回答1:


I am confused about the relationship with the Base Image and the host.

The only relation between the container and the host is that they use the same kernel. Programs running in Docker can't see the host filesystem at all, only their own filesystem.

it appears that you would have a much heavier footprint (akin to multiple VMs) on the host machine if you had a variety of base images running. Is this assumption correct?

No. The Ubuntu base image is about 150MB. But you'd be hard-pressed to actually use all of those programs and libraries. You only need a small subset for any particular purpose. In fact, if your container is running memcache, you could just copy the 3 or 4 libraries it needs, and it would be about 1MB. There's no need for a shell, etc. The unused files will just sit there patiently on disk, completely ignored. They are not loaded into memory, nor are they copied around on disk.

GOOD: Many containers sharing a single base image. BAD: Many containers running separate/unique base images.

No. Using multiple images will only use a tiny bit of RAM. (Obviously, multiple containers will take more disk space, but disk is cheap, so we'll ignore that). So I'd argue that it's "OK" instead of "BAD".

Example: I start one Ubuntu container with Memcached and another Centos container with Tomcat. If they were BOTH running Ubuntu, they could share the RAM for things like libc. But because they don't share the files, each base image must load it's own copy of libc. But as we've seen, we're only talking 150MB of files, and you're probably only using a few percent of that. So each image only wastes a few MB of RAM.

(Hint: look at your process in ps. That's how much RAM it's using, including any files from it's image.)




回答2:


For the moment, Docker is using AUFS which is a Union file system using the copy on write.

When you have multiple base images, those images take disk space, but when you run N containers from those images, there is no actual disk used. As it is copy-on-write, only modified files will take space on the host.

So really, if you have 1 or N base image, it changes nothing, no matter how many container you have.

An image is nothing more but a filesystem where you could chroot, there is absolutely no relation between an image and the host beside the fact that it needs to be linux binary form the same architecture.




回答3:


I think that multiple base images has just minor impact on memory used.

Explanation:

I think that your comparison to VM is a bit misleading. Sure, in case of f.e. 3 base images running, you will have higher memory requirements than in case of just 1 base image but VMs will have even higher memory requirements:

Rough calculation - Docker, for M images, N containers:

  • 1 x base image + N x container (file system + working memory)
  • M x size of base image + N x container (file system + working memory)

Calculation - VMs:

  • N x VM image = at least N x size of the base image for specific VM + N x size of container (size of file system + working memory)

For docker to gain advantage you have to have M << N. For small M and large N difference between docker and multiple VMs is significant.



来源:https://stackoverflow.com/questions/18601640/what-is-the-impact-of-using-multiple-base-images-in-docker

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!