Measure the difference between a container and a VM
Task
Run the same trivial application as a container and as a virtual machine, and measure start time, image size, memory overhead and density. The lesson asserts the differences; this lab produces your own numbers for them.
Steps
- Pick a trivial HTTP service. Package it as a container image and record the image size. Build a minimal VM running the same service and record the disk image size.
- Measure cold start for each: from the start command to the first successful HTTP response. Take five measurements each and record the median in
lab/compare.csv. - Measure memory: the resident set of the container versus the memory allocated to the guest.
- Start as many containers as you reasonably can and record the number before the host struggles. Do the same for VMs. Record both densities as rows in
lab/compare.csv. - On the host, find the container's process in the ordinary process list and record its PID as seen from the host and from inside the container, as a row in
lab/compare.csv. Write one sentence on what that proves about the isolation boundary. Then remove every container, image and VM created here.
Verify
awk -F, 'NR>1 && NF>=3 {n++} END {print n" measurement row(s)"}' lab/compare.csv
grep -Eci 'pid 1|pid=1|process list|shared kernel' lab/compare.csv
grep -Eci 'density' lab/compare.csv
The PID observation is the important one: seeing the same process with two different PIDs is the clearest demonstration that a container is a namespaced process rather than a machine.
This is an independent study companion for CompTIA Cloud+ CV0-004 and is not produced by or endorsed by CompTIA.