DEV Community

Ashlee (she/her)
Ashlee (she/her)

Posted on • Updated on

Explain Containers Like I’m Five?

I thought I understood containers for a second, but the more people tweet about them on Twitter, the more confused I feel. So, could you explain it like I’m five? 😊 I’ll also take any resources you have to share on the topic. Thanks, friends!


Did you know I have a newsletter? 📬

If you want to get notified when I publish new blog posts or make major project announcements, head over to https://ashleemboyer.com/newsletter.

Top comments (5)

Collapse
 
wuz profile image
Conlin Durbin

I think it helps to think about why they are called containers and how that differs from virtual machines.

If you think about shipping containers, they are these self-contained units of something, that you then stack up on a boat. A container by itself probably wouldn't float and it definitely wouldn't be able to move across the water. So the boat shares some of its resources with the container - like it's motor and it's floating ability. That is how containers work with their host operating system. The host system (let's say Ubuntu) shares some resources with the container. The container then does it's own thing, in its self-contained system. That container doesn't really care what kind of boat it is on - it will always contain the same thing, regardless of if it is on a battleship or a dinghy. The resources it has access to might change though.

In contrast, a VM is like a complete boat, floating in the pool of a cruise ship. It can move on its own and outside of some hardware resources doesn't really rely much on its host. That smaller boat has a bunch of stuff it doesn't need (like it's own motor), but it doesn't really know that. To that boat, it is still floating on water and might need those resources later.

Hope that helps!

Collapse
 
wuz profile image
Conlin Durbin

Here is a much better, more in-depth explanation of the same thing:

gsferreira.com/archive/2018/03/exp...

Collapse
 
banzyme2 profile image
ENDEESA

Great analogy

Collapse
 
nestedsoftware profile image
Nested Software • Edited

Docker is probably the most well-known kind of container. A container is a way of packaging up a piece of software so that it can be deployed in one step on any system, as long as it supports that container.

You set up everything needed by your software (db, web server, libraries, images, html, whatever) in the container and test it locally. If the software works, you can upload your container image to the cloud, or wherever, and it should continue to "just work"!

Consider the alternative: Let's say you have a linux machine at home that you're using for development. You've installed a variety of software and libraries on that machine, and you've developed a web app that works locally. How would you upload it to a production server? Chances are you'd have to write one or more bash scripts that try to install and configure everything to work on the target machine. However, that machine may be running a different flavour or version of linux, or a different shell, and your scripts might not work properly. On the other hand, once you've got your software working in a container like docker, then you can just deploy your docker image to another docker container. You don't have to run the installation and configuration of software again anymore.

Container images provide standardization of the environment while at the same time offering good performance characteristics, because the interface between the container and the host operating system is quite lightweight. There is probably quite a lot of variety in the details of how different container systems work, but I think this is the main takeaway from an eli5 point of view.

docker.com/resources/what-container

Collapse
 
theodesp profile image
Theofanis Despoudis • Edited

You have lots and lots of toys. A room full of it. Your parents are buying you more every day and as you like surprises. But your younger sister is growing up and also wants piece of the pie. You don't like that. You want to have your own special set of toys that only you can play. So you devise a plan.

First you tell to your mom to get you a box so you can put your toys. Then you ask her to move that box in your room so you can play them there instead of the living room. Then you tell your mom that you are a grown up girl now and don't want to be interrupted. You want privacy and control of how to play with your toys. You also want to set up your own rules on how and when your sister can play with you and share your toys with here.

Containers are like your toys. You are the container runtime and your mom is the host OS that guides you and takes care of the provision of resources. Your sister is another container runtime although you may be sharing this runtime under the rules of your parents. You and your sister are not sharing resources explicitly. She has her own toys and you have yours. When you want to share resource you declare for example that I have those toys to share. This is similar to docker volumes or networks where containers can use them if they are available.

When you ask for more toys, you use your parent to get a toy from the toy registry (akka Docker Registry of similar images) and give it to you. Then you can open the box and start playing (akka creating a container out of the image). Your sister can ask a similar toy or can ask a different toy from the toy registry. Now each toy you have can be customised, for example you have a barbie doll and you can add accessories (add additional layers in the docker container). Your sister also can have her own barbie doll with a different set of accessories.

I hope your 5 year old self understood what containers are.