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.
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ā¦
ā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?
- 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.
- 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
- 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.
šÆ
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!