r/AskComputerScience • u/h0peless_b4stard • 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!
7
Nov 16 '18
Yo dawg, I heard you like computers, so I put a computer inside your computer so you can compute while you compute
3
3
u/xiongchiamiov Nov 16 '18
From a user's perspective, Docker containers are like VMs with a couple of caveats:
They only run one process each.
They have to run Linux.
They don't have the same security sandboxing.
They're "lightweight" so you can run a bunch of them.
That last one has a lot of implications, because it means you can separate out everything. So for instance, a web server generally has three or four important things running on it, and with containers you'd put each one in its own pseudo-vm, which in turn means you can manage their dependencies independently (say, php is running on Ubuntu but nginx is running on centos).
Also, importantly, containers solve a lot of old problems that we understand well and create new problems that we don't. ;)
1
u/h0peless_b4stard Nov 16 '18
That's a good and concise analysis and the I love the conclusion haha thank you so much!
3
u/novarising Nov 16 '18
I am not advanced by any means and I am still not sure what docker is exactly, but I know at least this much that domiquec is wrong, he is describing VMs. A computer within a computer.
A VM is what simulates the whole hardware and then you can run your stuff inside it. Containers don't simulate anything, they run on the same hardware but you can think of it as compartmentalizing and running stuff in these private self contained compartments. They work on shared resources so they don't have as much overhead as a VM.
I may not be completely correct in everything, so I'll wait for someone to bring a better explanation. :)
1
u/h0peless_b4stard Nov 16 '18
Thanks! I do understand and use VMs daily but the whole Docker thing was just revealed to me and I couldn't see the purpose/difference. I think I start to get it now.
3
Nov 16 '18
VMs share a cpu, containers share a kernel. Read this -> https://blog.jessfraz.com/post/containers-zones-jails-vms/
1
u/OHotDawnThisIsMyJawn Nov 16 '18
For people who are interested this is a really great and accessible series of articles describing cgroups
https://lwn.net/Articles/604609/
Cgroups are the technology that enabled the creation of docker
-4
u/dominiquec Nov 16 '18
Docker allows you to run a computer within a computer, basically like the movie Inception where they can have a dream within a dream.
The real physical computer you're running on is called the host. The virtual computer that's running on the real computer is called a container. Containers are made from a template called an image. Images in turn are assembled from recipes called Dockerfiles.
Docker makes it easy for developers to deploy programs because they just write Dockerfiles which assure consistent images and containers. Dockerfiles define what operating system and programs to put into an image, and how to run those programs.
Hope this helps!
9
u/EquationTAKEN Nov 16 '18
I feel like you're describing VMs instead of containers.
2
u/pilibitti Nov 16 '18
I don't think that anything /u/dominiquec wrote is technically incorrect with regards to docker. The system runnin in a VM or docker backend is an implementation detail. Docker images run and feel like "virtual machines" without consuming the resources of a full fledged VM because the OS kernel provides support for it. In an OS that doesn't natively support it (such as macOS) docker runs in a VM - but in a single VM.
Again, I thinkit is an implementation detail - you can do the same with vagrant - the semantics are very similar. How they achieve the goal is different. With docker, there still is a separation for running environment, network abstraction etc. consumes far less resources and that is its entire point against VMs and / or something like vagrant.
5
Nov 16 '18
[removed] — view removed comment
3
u/cguess Nov 16 '18
You’re technically right but for someone who’s at the level of “what is Docker” it’s probably the best analogy. You get a (more or less) separate file system, networking rules etc.
2
u/PC__LOAD__LETTER Nov 16 '18
It’s not the same as a virtual machine but it’s not correct to say that it’s “not like” one.
0
Nov 16 '18
In what way is it not?
4
u/PC__LOAD__LETTER Nov 16 '18
Containers split up available resources and provide some protections between containers, but nothing is virtualized. The same kernel is handling all of the requests being made by things running the containers. VMs on the other hand include their own OS.
2
u/h0peless_b4stard Nov 16 '18
This is a nice explanation. I do understand VMs and this kind of clarifies the differences and advantages.
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.