
- Create a virtual machine and observe how it behaves.
- Run containers with Docker and compare startup time, isolation, and persistence.
- Walk through practical use cases for VMs and containers at home, at work, and in the cloud.



- Resource allocation: VMs are provisioned with virtual CPU, RAM, and disk. In this demo the Windows XP VM is assigned ~0.5 GB RAM and ~1.7 GB disk. Never allocate more physical RAM to VMs than your host actually has — doing so can cause swapping or instability. Some hypervisors support memory overcommit/ballooning, but that can reduce stability under pressure.
- Boot time: When I click Start, the Windows XP VM boots. On this setup it takes about a minute from power-on to usable desktop — far slower than containers.
- Isolation and security: A VM is isolated from the host. Actions inside a VM stay inside the VM unless you intentionally share resources (files, clipboard, network). However, a network-connected VM can be exposed to the internet.
Do not log into real accounts or handle sensitive data inside an unpatched or unsupported VM. Even with isolation, a network-exposed VM can be compromised.

- Strong isolation or running a different OS than the host.
- Persistent environments for testing, legacy applications, or software that requires a full OS.
- In the cloud, renting full VMs to host services or test environments.


- A short-lived container with rancher/cowsay:
docker runcreates and runs a new container.rancher/cowsayis the image (userrancher, imagecowsayon Docker Hub).kode-kowis the text cowsay prints.
- A long-lived web server (Nginx) mapped to a host port:
-druns the container detached (in the background).-p 8888:80maps host port8888to container port80. Visithttp://localhost:8888to see the Nginx welcome page.
nginx:latest isn’t local, Docker pulls it first. Containers start quickly — usually in a fraction of a second — which is a major difference compared to VM boot times.
If you need a shell inside a running container:
-itallocates an interactive TTY.- You can use the shortened, unique prefix of the container ID.
http://localhost:8888/test.txt to verify persistence inside that running container.
Important difference vs VMs: containers are ephemeral. If you remove this container and start a new one from the same image, the new container starts with a clean filesystem and your file will be gone unless you persisted it externally.
Persisting data with Docker volumes
To retain files beyond a container’s lifetime, use a Docker volume:
-v my-nginx-data:/usr/share/nginx/htmlmounts a named volume (my-nginx-data) at the Nginx web root.- Files written to that path are preserved in the volume and available to future containers that mount the same volume.
Use named volumes to persist data independently from container lifecycles. Volumes are the recommended way to keep data when containers are removed and recreated.
- Fast startup and lightweight isolation.
- Ideal for microservices, CI/CD, and ensuring consistent environments across machines.
- At home for experimenting with apps; in teams for reproducible development environments; at scale in production for dynamic scaling and rolling updates.

| Command | Purpose |
|---|---|
docker run rancher/cowsay kode-kow | Pulls (if needed) and runs a short-lived container that prints kode-kow. |
docker ps -a | Lists all containers, including exited ones. |
docker run -d -p 8888:80 nginx | Runs Nginx in the background and maps host port 8888 to container port 80. |
docker exec -it <CONTAINER_ID> sh | Opens an interactive shell inside a running container. |
docker run -d -p 8080:80 -v my-nginx-data:/usr/share/nginx/html nginx | Runs Nginx with a named volume to persist web content. |
| Resource | Virtual Machines | Containers |
|---|---|---|
| Kernel | Own guest OS kernel | Share host OS kernel |
| Isolation | Strong (hardware-level virtualization) | Namespace/cgroup isolation |
| Boot time | Minutes (full OS boot) | Milliseconds–seconds |
| Size | Large (GBs per VM) | Small (MBs per image) |
| Data persistence | Virtual disk persists by default | Ephemeral by default; use volumes for persistence |
| Use cases | Running different OSes, legacy apps, strong isolation | Microservices, CI/CD, scalable apps |

- VMs (UTM, VirtualBox, VMware) run full operating systems and provide strong isolation — useful for legacy systems and running different OSes.
- Containers (Docker, Podman, containerd) are lightweight, fast to start, and portable — ideal for modern application development and scaling.
- Use volumes to persist container data; rely on VM virtual disks for persistent VM state.
- Choose VMs when you need full-OS isolation; choose containers when you need speed, portability, and efficient resource utilization.