在Docker中使用多个Base Images的影响是甚么? [英] What is the impact of using multiple Base Images in Docker?

查看:199
本文介绍了在Docker中使用多个Base Images的影响是甚么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我明白码头箱容器在Docker主机之间是可移植的,但我对与Base Image和主机的关系感到困惑。



图像上的文档,如果运行了各种基本映像,似乎在主机上的脚印(类似于多个虚拟机)会更重。这个假设是否正确?




  • GOOD :许多容器共享一个基本图像。

  • BAD :许多容器运行单独/唯一的基本图像。



我确定很多这种混乱来自于我对LXC的缺乏认识。



解决方案


我对与Base的关系感到困惑图像和主机。


容器和主机之间的唯一关系是它们使用相同的内核。在Docker中运行的程序根本看不到主机文件系统,只能看到他们自己的文件系统。


似乎你会更重如果运行了各种基本映像,主机上的脚印(类似于多个虚拟机)。这个假设是否正确?


否。 Ubuntu的基本映像大约是150MB。但是,您实际上不得不使用所有这些程序和库。您只需要一个小的子集用于任何特定的目的。实际上,如果你的容器运行memcache,你可以复制所需的3或4个库,大约是1MB。没有必要的shell等等。未使用的文件只会耐心地坐在磁盘上,完全被忽略。它们没有加载到内存中,也不会在磁盘上复制。


好:许多容器共享一个基本映像。
BAD:许多容器运行单独/唯一的基本映像。


否。使用多个图像只会使用一点点的RAM。 (显然,多个容器将占用更多的磁盘空间,但磁盘便宜,所以我们忽略)。所以我认为这是OK而不是BAD。



示例:我用Memcached启动了一个Ubuntu容器,另一个使用Tomcat启动了一个Centos容器。如果他们是BOTH运行Ubuntu,他们可以共享RAM,例如 libc 。但是因为它们不共享文件,所以每个基本映像必须加载它自己的副本 libc 。但是正如我们所看到的,我们只是说150MB的文件,你可能只使用其中的百分之几。所以每个图像只会浪费几MB的RAM。



(提示:在 ps 中查看你的进程。它使用了多少RAM,包括其图像中的任何文件。)


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.

解决方案

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

这篇关于在Docker中使用多个Base Images的影响是甚么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆