Learning paths / Cloud foundations / Servers and compute

Virtual machines and containers

Reading · 5 min · Module 2, lesson 3 of 410 min left in this module

Module 2 · Servers and computeLesson 3 of 4

Goal: Explain how virtual machines and containers split one physical machine, and why apps ship as containers.

3:14 · captions and chapters · narrated with an AI-generated voice
Transcript

Narration uses an AI-generated voice.

[00:00] One machine, many computers

By the end of this video, you'll know what a virtual machine and a container each share with the machine underneath them. That one difference explains why containers start in seconds, and why so many apps now ship as containers.

Let's start at the bottom, with one physical machine in a data center. Real CPU, memory and disk. It's far bigger than most apps need. So a program called a hypervisor divides it up. Each slice is a virtual machine, with its own share of CPU, memory and disk. And each one believes it's a whole computer.

[00:39] What a VM shares

So what does a virtual machine share with the machine underneath? Just the hardware. Everything above that, it brings itself. Including a full operating system. That's why VMs are strongly separated. A customer on one can't see into another on the same hardware. It's what lets a provider rent one machine to many strangers, safely. The price is weight. Every VM carries a whole operating system, and boots like a real computer.

[01:12] What a container shares

Now look inside one virtual machine. Here, the apps run as containers. A container packs your app with what it needs to run. The language runtime, libraries and files. But not an operating system of its own. So what does a container share? The kernel. That's the core of the operating system, the part that talks to the hardware. Every container on this machine shares that one kernel. There's nothing to boot. The kernel is already running, so a container starts in seconds.

[01:47] Images and layers

A container starts from an image. That's a read-only snapshot of your app and everything it depends on. Build the image once. Then it runs the same on your laptop, on a test server, and in production. Same libraries, same versions, every time. That's the cure for "it works on my machine".

These layers stack. A provider rents out virtual machines. A platform runs containers on top of them. And you hand the platform your image. You pick the layer to work at, not every layer beneath it. On ComputeSphere, every service runs as a container. You bring the image, or let ComputeSphere build it from your repository.

[02:33] Recap

So, the one difference to remember. A virtual machine shares the hardware, and brings its own operating system. Heavy, strongly separated, and slow to boot. A container shares the kernel, and brings just your app. Light, and it starts in seconds. Need control of the operating system itself? Choose a VM. Want to ship your app the same way everywhere, and replace copies in seconds? Choose containers.

Now try the checkpoint at the end of this lesson. I'll see you in the next one.

Key idea

When you rent a server, you almost never get a whole physical machine. You get a virtual machine, one slice of it with its own operating system. Inside that, apps increasingly run as containers: lighter slices that share one operating system and start in seconds.

Virtual machines: many computers in one

A physical server in a data center is far bigger than most apps need. A program called a hypervisor divides it into virtual machines. Each gets its own share of CPU, memory and disk, and believes it's a whole computer.

Because each one runs a full operating system, VMs are strongly separated: a customer on one can't see into another on the same hardware. That's what lets a provider rent one machine to many strangers safely. The price is weight: every VM carries a whole operating system and boots like a real computer.

Containers: just your app and what it needs

A container packs your app with everything it needs to run, such as the language runtime, libraries and files, but not an operating system of its own. Every container on a machine shares that machine's kernel, the core of the operating system that talks to the hardware.

A container starts from an image: a read-only snapshot of your app and its dependencies. Build the image once and it runs the same on your laptop, a test server and production. That's the cure for "it works on my machine".

The limits that matter from the last lesson still apply. A container can be given a share of CPU and a memory limit, and one that goes over its memory limit is stopped.

Which one you get

These layers stack. A provider rents out VMs; a platform runs containers on top of them; you hand the platform your image. You pick the layer to work at, not every layer beneath it.

  • Choose a VM when you need to control the operating system itself.
  • Choose containers when you want to ship an app the same way everywhere, and start or replace copies in seconds.

The Containers path teaches how to build images of your own.

Check yourself

Why does a container start in seconds while a virtual machine can take minutes?
Your app runs on your laptop but fails on the server because a library version differs. What fixes that for good?

In the docs