What **is** Docker? šŸ¤·šŸ¼ā€ā™€ļø

JavaScriptāž•CoffeešŸš€ - Sep 20 '20 - - Dev Community

Terms:
OS: Operating System
VM: Virtual Machine
Server: Big olā€™ hunk of metal with some wiry bits
Orchestrator: Something that runs on a website and manages what everything does
Messaging system: Not MSNā€¦ in a website, the messaging service essentially runs back and forth between different components and pieces of your site and takes messages from one thing to the other.
Host OS: The base operating system for your machine
Guest OS: Created by a VM

Iā€™m going to set a scene here that we are going to keep referring back to.
Youā€™ve built a website for a big idea. Itā€™s got a form that a user can submit, and itā€™s got a bunch of other snazzy features. You are very pleased with this and want to take the idea further. You need some help from Randall the developer. Randall is a cool guy. He loves burritos šŸŒÆ
To build your website, you are running 3 different OSs, as your essential apps and features run on different operating systems.

Essential app A: Linux version 6.6
Essential app B: Windows
Essential app C: Linux version 5.1

Before we jump straight into Docker, I think itā€™s important to have some historical context.
Before Docker, and before containers, data was stored and accessed on servers, which are stored in giant fridges called data centres. Every one of these servers holds 1 OS, and they are pretty expensive.

A cabinet holding servers. Wires are plugged in
Back to you and Randall. On top of paying Randall for his excellent skills, youā€™re paying top dollar for three servers! Thatā€™s 3 big hunks of metal, and 3 payments to store them in a data center! Thatā€™s going to add up $$$ā€¦

This is why hypervisors were invented.

Hyper...what?

Hypervisors are essentially used to split up the memory and storage on a server. This means that you can have one server for multpile OS systems. Oooooooohhhhhhhhh. Exciting stuff.
Let me explain:

Imagine for a second that your server has turned into a big rectangular pizza.

Stay with me, stop thinking about pizzaā€¦
A round pizza on a table, cut into portions

ā€˜You have 3 very fussy people coming over for dinner. You need to feed them all. They all eat different things, and donā€™t like anything else. You also need to eat - so what will you do? Itā€™ll be very expensive to make 4 different pizzas...
You are going to make one huge pizza, but with 4 different flavours in each corner. You decide on the topping, and the amount of toppings, and then bake it in the oven.ā€™

Now Iā€™ll say that analogy again but with some different words

ā€˜You have 3 important applications that run in your website. They all require an OS. They all run on a different OS, they canā€™t run on anything else. Remember your 3 servers? Itā€™s very expensive to run and keep them all. Your website is also running through something - called Node.js. This is a little more flexible and can run through most OSs.
You are going to have one server, but with 4 different OS running on it. You can also decide on the distribution of resources such as CPU, RAM, and all sorts.ā€™

This is basically what a hypervisor does - you can split your resource (your server) to run multiple OS and assign it as much memory and power as you need (limited to the capacity of your server.) - this way you can run all of your applications (feed all of your fussy guests) on one server, rather than having multiple servers!

A hypervisor also sits under your VMs and provides the base for them. You may have heard of VMs before. Say you and Randall are running your website on your Linux machine, but you really need an application in your site that runs only on Windows. Uh oh. But itā€™s ok because VMs exist! You can spin up a Windows machine inside your Linux machineā€¦.. Confusing. But that is what hypervisors and other VMs do.
The most popular type of hypervisor is VMware, specifically ESXi.

Great, but does that explain Docker?

No.
Docker is actually more like a single server with a hypervisor on top...

The big difference is that a VM virtualises the hardware - this causes the OS to believe that it in fact does have the correct hardware (kernel) to do what it needs to do. In essence, the VM is ā€˜foolingā€™ the OS.
Docker, on the other hand, sees what you want to run, and then provides an interface for the programs inside it (that all run on different versions and are a nightmare). It puts them into little virtual boxes, or containers. It is similar to how a VM would do it, but it is itā€™s own little box, rather than a virtualisation of hardware, and the creation of a ā€˜guest OSā€™ (tricking the host OS into thinking it has the ability to run) And it will perform better doing this due to the fact that it uses the base OS kernel, rather than creating something on top of it as a VM does.

Kernelā€¦?

The kernel is a computer program at the core of your computer's OS with complete control over everything in the system. Every OS has one. Your Windows computer has a Windows kernel, your Ubuntu system has a Linux kernel and so on.

You can read more about the kernel in this article

So why is Docker so popular?

Why is the industry going mad for docker right now?

  1. Faster onboarding

This point is pretty self explanatory.
Let's go back to you and Randall.
We already know that you have a Linux machine and you have built your site with Node. So Randall needs to install and get Node up and running. You also have a form on the site, and behind that is a database. So Randall needs to install and get familiar with MongoDB, which you have used. Randall also needs to download, install and get familiar with the site orchestrator and the messaging system

Thatā€™s quite a lot to do, and you havenā€™t even started with Randall on your vision for this workā€¦


Letā€™s pull this scenario over to a universe where you are using Docker.

Hereā€™s that same scenario:

Randall needs to install and get familiar with Docker.

Thatā€™s...it.
You can get on with explaining your vision for your website.

Children pointing at a laptop screen and celebrating

  1. Itā€™s portable

This may sound strange, as it may feel like everything on the internet is portable - that is, you can access stuff on pretty much any machineā€¦

You know that joke of developers saying to testers ā€˜well, it works on my machine!ā€™?
If they arenā€™t using docker, then it might be true! We already learned from Randall that some things on your website require different OSs, and have different dependencies (above the kernel level) to runā€¦ so if a developer builds a lovely shiny thing and doesnā€™t build it through docker, then they are relying on everyone that they send it to having the necessary stuff in order to run it!
Docker just wraps all of the code up in OS boxes, or containers, and runs them everywhere and anywhere! This also means that the code can be built by Docker anywhere, allowing for more fluid collaboration between teams.
You must be careful though - if you and Randall build something that references something external, Docker wonā€™t be able to put that into a container - so it may not work as expected on another machine that doesnā€™t have the external thing

  1. Itā€™s fast....

So it isnā€™t technically true that Docker is faster than VMs, but it performs better due to the fact that Docker shares the host kernel - it is more efficient and therefore your computer will run smoother - I suppose this gives the impression that it is faster.

It is not wrong to say that it is faster - technically it is - but Iā€™ll leave it up to you if you want to start a fight with someone about it! Ok so it is faster, but it is faster because of the better performance, not because it is inherently just faster.Inside the container (where your website and its contents are happily running), it performs about the same as a VM, but the act of actually having a VM running on your machine is quite performance draining.

To sum up - Docker is essentially a speedy burrito, full of code.
šŸŒÆ
2 burritos on a square white plate

Thank you to:

Many YouTube videos, particularly
Network Chuck - https://www.youtube.com/watch?v=eGz9DS-aIeY
Many folks on Twitter, particularly:
@mesetatron - for your incredible subject knowledge and clarity of points
ā˜•ļøCoffee - a staple of my diet
šŸµTea - so many cups of tea
šŸ¦Ice cream - 1 tub of ice cream was consumed!

. . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player