- Create and run a virtual machine and observe behavior.
- Create and run containers with Docker and observe behavior.
- Compare boot time, isolation, resource usage, and persistence.
- Wrap up with real-life use cases for VMs and containers.

Virtual machines (VMs) — demo with UTM (type‑2 hypervisor)
Virtual machines run a full operating system in a hosted environment. For this demo we use UTM (a type‑2 hypervisor). Other common hypervisors include VirtualBox and VMware Fusion depending on your OS. Key considerations when creating a VM- Resource allocation: assign RAM and disk space carefully — e.g., assigning 0.5 GB RAM and ~1.7 GB disk requires that the host have at least that much free memory and storage.
- Never assign more RAM to a VM than the host physically has if you want predictable performance. Some hypervisors support memory overcommit, but that can lead to swapping and degraded performance.
- A VM boots a full OS. In this setup, Windows XP boots in ~1 minute. We’ll compare this to container startup times later.
- VMs provide strong isolation: if a VM becomes compromised, you can delete the virtual disk and rebuild the VM.
- Isolation is not absolute: network-enabled VMs remain reachable from the internet unless you restrict access. Avoid using real accounts or sensitive data inside unpatched or unsupported VMs.
Unpatched or unsupported VMs (older OS builds) can be vulnerable to attacks. Treat any VM with internet access as potentially unsafe—do not store real credentials or sensitive data inside them.
- VMs use a virtual hard disk. Files you create inside the VM persist across reboots and power cycles because they are written to the VM’s virtual disk.
- Example: saving a Minesweeper high score inside the VM, shutting down, and restarting — the score remains.
- Home: test risky apps or try a new OS without altering your main system.
- Workplace: run legacy systems that cannot be updated.
- Cloud: rent full VMs from cloud providers (e.g., AWS EC2) to host dev/test or production workloads.
Containers with Docker
For containers this demo uses Docker Desktop. Docker Desktop runs on macOS, Windows, and Linux and provides an easy way to build, share, and run containerized apps.- Docker Hub is a public registry for container images (like an app store for images). Images pack the application code, dependencies, configuration, and runtime instructions.
- When you run an image that isn’t present locally, Docker pulls it from Docker Hub automatically.

Basic Docker examples
- One-shot container: rancher/cowsay
- Long-running container: nginx
-druns the container in detached mode (background).-p 8888:80maps port 8888 on the host to port 80 inside the container.
- Containers share the host kernel but run in isolated user-space environments. On Linux, containers use the host kernel directly. On macOS and Windows, Docker Desktop runs a lightweight VM that provides a Linux kernel for containers.
- Containers cannot access other containers or the host unless you explicitly grant filesystem mounts, network access, or extra capabilities.
- Docker Desktop provides per-container CPU and memory statistics for monitoring resource usage.
- If you prefer not to install Docker locally, use a browser-based Docker playground to run the same commands. Behavior is the same: one-shot containers exit after producing output; long-running containers stay active and can be accessed via the playground’s port-forwarding UI.
Persistence inside containers
By default, files written inside a container’s writable layer are ephemeral: removing the container deletes those files. To persist data, mount a host directory or use a Docker named volume. Example: add a file inside a running Nginx container- Files written to
~/nginx-dataon the host will persist even if you remove and recreate the container.
Containers are designed to be fast, portable, and disposable. Use Docker volumes or host mounts to persist important data across container restarts or recreations.
Quick comparison: VM vs Container
Real-world use cases
- Home: run risky apps, sandbox new OS versions, or experiment without modifying the host.
- Development teams: use containers to ensure consistent environments across dev, CI, staging, and production.
- Enterprises: run scalable microservices, CI pipelines, and thousands of containers to deploy updates rapidly.
- Cloud: use VMs when you need a full OS or strong isolation; use containers for portable, scalable app workloads.
Summary
- VMs (e.g., UTM, VirtualBox, VMware) run full operating systems with strong isolation and persistent virtual disks. They’re well suited for legacy apps, full OS testing, or scenarios requiring strict isolation.
- Containers (e.g., Docker, Podman, containerd) run lightweight, isolated user-space environments that share the host kernel. They are ideal for fast, portable application deployment and scalable architectures.
- This walkthrough demonstrated differences in boot time, isolation, and persistence, and provided hands-on commands you can try locally or in an online playground.
Links and references
- UTM — getutm.app
- VirtualBox — virtualbox.org
- VMware Fusion — vmware.com
- Docker Desktop — docker.com/products/docker-desktop
- Docker Hub — hub.docker.com
- Kubernetes Basics
- AWS EC2 course on KodeKloud