Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

docker

lxc

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.

enter image description here

like image 986
Page Avatar asked Sep 03 '13 21:09

Page


2 Answers

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

like image 158
BraveNewCurrency Avatar answered Sep 18 '22 16:09

BraveNewCurrency


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.

like image 31
creack Avatar answered Sep 18 '22 16:09

creack