Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker: How to create a stack, multiple images or one base image?

I am new using Docker, and I got the doubt of using one image base for my stack or I have to define each image depending on my needs.
For example, reading a blog about creating a website using docker the author suggests the following Stack: enter image description here

Image taken from http://project-webdev.blogspot.de/2015/05/create-site-based-on-docker-part4-docker-container-architecture.html
Now, seen the structure, If we have base images in the Docker registry for technologies as mongoDB, io.JS, nginx, Why on this examples we do not use those images insted of using a single Docker base image for everything?

like image 805
eduartua Avatar asked Jun 10 '15 14:06

eduartua


2 Answers

I'm the author of this blog post/series, so let me elaborate on the reason why I've chosen one base image. :)

Docker offers the possibility to use a common base image for subsequent images, so you can stack all images and each image only contains the diff to the underlying image (that's the big advantage of docker!). You can save disk space and RAM. If you don't care about that (I mean RAM and storage are cheap) you can also use multiple images.

Another advantage of one base image is that you can configure/secure that base image based on your needs. If you use a different base image for each container, you have to maintain all of them (e.g. firewall) and Docker will download several different images (uses more disk space, container builds take longer)).

But what's the difference when you look at the official images? The official mongodb, redis and MySQL images are based on the debian:wheezy image. So if you use these images, they will also be based on the same base image, won't they?

Anyway, if you want to use your own architecture, feel free... please consider this architecture/blog post as possible idea of creating a Docker setup. Thanks to Docker and they way it shares the kernel, you can use as many images you want. :)

Regards,

Sascha

like image 181
Sascha Avatar answered Oct 30 '22 18:10

Sascha


i suppose it depends on the application but in this case you are right it does not make sense to have a large base image.

From my understanding, the author created a base image and then built a lot of other images from that base image. When you build an image for docker, there are a lot of intermediary images created so if the base image is the same, it could be shared and potentially save some memory on your machine.

but i don't think it makes any difference for when you run the containers. each container is independent and they essentially only share the linux kernel. and it's actually really bad because the base image is huge in this case and it takes a lot of resource to spawn up a container from an image like this. the dedicated images for each service are much smaller and take up much less resource for when you start containers from them. so yea, whatever memory you could save from building a large base image is not going to be worth it.

like image 22
lingxiao Avatar answered Oct 30 '22 19:10

lingxiao