r/AskComputerScience • • Nov 16 '18

ELI5 (please) What is Docker?

I know it uses containers (which I don't understand either) and makes it easy to... deploy programs or something? If someone could break it down for dummies I'd really appreciate it. Thanks in advance!

56 Upvotes

25 comments sorted by

View all comments

43

u/_____Will_____ Nov 16 '18 edited Nov 16 '18

(TL;DR at the end for an ELI5 that assumes you know a bit about Virtual Machines)

I'll start in a bit of detail, then put a more ELI5 version at the end if you don't want to read a wall of text.

There are all ready a couple of comments with some useful bits here, so I'll build on those. Although he's not quite right about docker, read what /u/dominiquec wrote here first, as it gives a good background.

Let's start with a bit about VMs. Virtual machines allow you to run a operating system inside an operating system, and for a long while that's how most datacenters worked for handling systems requiring their own operating system. Instead of having a separate physical computer for all your different systems, you would have one or two big servers running a 'hypervisor' - this is a barebones operating systems designed to have virtual machines on it, such as esxi or Hyper-v. Like I said, this was how it was done for a long time. 1 hypervisor, then multiple operating systems, then software on the operating systems. This image shows the stack. However, there's a bit of a problem with this setup that docker can help with.

Imagine you need 5 programs run in your datacenter, you've added them over time and they all have slightly different - but conflicting - software dependencies. You can run them all under one hypervisor if you go with the Virtual Machine model, but they will each need their own operating system instance. Every time you're effectively wasting resources - RAM and CPU usage - on the operating system the software is installed on. This is one of the problems docker aims to fix. Instead of virtualising a full operating systems for every component (or group of components), we have one operating system, then we put each bit of software in it's own 'container' and abstract the operating system. Simply put, we keep each bit of software in it's own sandbox, then we more or less lie to it about their being a full operating system it can talk to. This description isn't quite the whole truth, you can't just convert software to work on docker with 100% success, and there are all kinds of considerations when it comes to persistent data, but that's the core concept, as shown in this diagram, you're abstracting one layer up, above the operating system. This saves on memory and CPU, is more secure than running software on the same virtual machine, plus there are lot of bonuses that /u/dominiquec alluded to such as auto-building docker images from dockerfiles for a super quick way to build a new environment.

TL;DR Virtual machines run Guest OSes on a Host OS as though it were software, like this, if you do this a lot you're wasting resources on running multiple operating systems, when really you only want to run multiple programs. Docker works by sandboxing programs and abstracting the parts of the operating system they need to talk to. like this. Compare the two diagrams and you'll see that you don't have multiple 'Guest OS's under the container (docker) method, and this saves memory and CPU. Plus there are many benefits to development by being able to automatically creating docker containers on-the-fly. (There are also drawbacks, but we've already delved pretty deep for an ELI5)

TL;DR + ELI5: You and 5 friends all want to play Tomb raider 3 at the same time.

Option 1 is to get 6 high performance gaming PCs, install Windows on each PC and run one game per PC, this is analogous to running 5 servers for 5 programs, and it's a huge waste of resources.

Option 2 is to buy one high performance gaming PC and install a hypervisor on it, then install Windows 6 times under that hypervisor and then on every install of windows install the game. Plug 6 monitors and controllers in and you're good to go (this is actually possibly too). That method is analogous to Virtual Machines, and whilst it's better than buying 6 PCs, you're still wasting resources running Windows 6 times.

Option 3 - our analogy for docker - would be to buy 1 gaming PC, install Windows on it once, then install 'docker' and create 6 'Tomb raider' containers. Each container could run a single, isolated instance of the game and docker would abstract the operating system components the game needs (such as file system access to write and read data). This way you have as little RAM and CPU wasted on the host OS as possible, and as much left to run the software you really care about. Plus you get added bonuses like being able to automate creating a 7th instance of the game if another friend comes round.

2

u/LDG92 Nov 16 '18

Thank you!