Why virtual machines
Several pretend computers can share one real one
A virtual machine is a pretend computer. Several share one real machine that would otherwise sit idle.
Why would anyone want a computer inside a computer? Picture an office with three servers: one for mail, one for files, one for the web site. Each does one job, and each sits idle most of the day. Now run all three as pretend computers inside one real server. Each still has its own operating system and cannot see the others. The office buys, powers and cools one machine, not three.
Three ways to run software
A virtual machine brings its own operating system
A virtual machine has its own operating system. A container shares the host's.
There are three ways to run software on a computer. On bare metal, one operating system owns the hardware, and the applications run on it. With virtual machines, a hypervisor divides the hardware, and each machine brings a complete operating system of its own. With containers there is one operating system, and each container holds only an application and the libraries it needs.
Hypervisors
A hypervisor runs on the hardware, or on an operating system
Type 1 runs directly on the hardware. Type 2 is a program on your own system.
The hypervisor is the software that creates and runs virtual machines, and it comes in two types. Type one is installed directly on the hardware, in place of an ordinary operating system. Running virtual machines is all it does. Type two is a program installed on Windows, macOS or Linux, beside your other programs. Its virtual machines appear in windows.
Hypervisors · Going deeper
Virtual network modes
Bridged joins the network. NAT hides behind the host. Host-only stays inside.
Sharing a host
Processor time can be promised twice. Memory cannot.
Virtual processors may exceed the cores. Memory must fit.
Here is one host shared by four virtual machines. It has sixteen processor cores. The four machines have been promised twenty-four virtual processors between them: one and a half for every real core. That works, because they are rarely all busy at once. The host has sixty-four gigabytes of memory. The machines are promised fifty-six, leaving eight for the host itself. This total must fit.
Snapshots
A snapshot freezes the disk and records changes beside it
After a snapshot, changes go to a separate file. Reverting discards them.
A virtual machine's drive is just a file on the host, and that allows something a physical machine cannot do. Normally the file is read and written. Take a snapshot, and the file is frozen. Changes from now on go to a second file beside it. A week later that second file holds six gigabytes of changes. Revert, and the changes are thrown away. The machine is exactly as it was.
Containers
A container carries the application, not a kernel
An image holds the application and its libraries. The kernel is the host's.
A container is built from an image. The image is a stack of layers: base system files, then a runtime and libraries, then your application. There is no kernel in it. Every container uses the kernel of the host. That is why it is so small. A base image is eight megabytes, or seventy-eight, where a Windows virtual machine needs at least sixty-four gigabytes.
Choosing
Choose by what must be kept apart
A different operating system needs a virtual machine. A portable application suits a container.
Which one to use depends on what you need to keep apart. A program that needs another operating system, or a file you do not trust, belongs in a virtual machine. So does old software that needs an old system, and so does testing an update: try it on a copy first. Virtual desktops keep company data in the data centre. And a service that must run identically everywhere is a job for a container.
Where to go for more
Containers have a course of their own
For containers in depth, take Containers and Cloud Native. Next here: mobile devices and printers.
Lesson complete
You finished “Virtual machines and containers”
Nicely done.