Exercise: Container vs. VM Network
Comparing Isolation
1 Purpose
This exercise provides a practical demonstration of the fundamental difference between a virtual machine and a container: a VM runs its own, separate kernel, while a container shares the host’s kernel. You will use command-line tools to inspect the network stack and kernel version of a running VM and a running container to see this difference firsthand.
2 What You’ll Accomplish
By the end of this exercise, you will be able to:
- Use
ip aanduname -rinside a VM and a container. - Use
podman execto run commands inside a running container. - Compare the outputs to explain the difference in kernel isolation.
This exercise maps to the following program and course learning outcomes:
- Course Learning Outcomes (CLOs):
- 1. Identify hardware and basic network components: This exercise highlights the key architectural difference between two primary virtualization technologies.
This exercise develops the following skills, which align with the O*NET SOC Code 15-1232.00 for Computer User Support Specialists.
| Learning Objective | O*NET KSAs | Technologies Used |
|---|---|---|
| Compare kernel isolation between VMs & containers. | Knowledge: Computers & Electronics Abilities: Category Flexibility, Deductive Reasoning |
uname, ip, podman exec |
3 Prerequisites
This exercise requires: - A running Fedora 42 VM (your main exercise environment). - A running traditional VM created in virt-manager (from Exercise 9.1). - A running Podman container (from Exercise 9.2). For this exercise, let’s start a simple one that will stay running.
Open a terminal in your Fedora VM and run the following command to start a container that sleeps indefinitely. We’ll name it my-comparison-container.
podman run -d --rm --name my-comparison-container --network bridge docker.io/library/alpine sleep infinityWhy use --network bridge?
By default, Podman may use the host network if the bridge network is unavailable or misconfigured, causing the container to share the host’s interfaces and IP. Specifying --network bridge ensures the container gets its own virtual network interface and IP address, demonstrating true container network isolation.
4 Step-by-Step Guide
4.1 Step 1: Inspect the Virtual Machine
Open the console for the VM you created in
virt-manager.Log into the VM.
Once you have a command prompt inside the guest VM, run the following two commands.
# View network interfaces ip a # View the running kernel version uname -rAnalyze the Output: Note the IP addresses; they are on a separate virtual network. Most importantly, note the kernel version. It is likely different from your main Fedora host’s kernel version.
4.2 Step 2: Inspect the Application Container
podman exec -it to get a terminal inside the container
If you don’t already know how to open a shell inside a running container, here’s how:
# Replace 'my-container' with the actual name of your container
podman exec -it my-container /bin/shNow, let’s run the same commands inside the Podman container. We will use podman exec to do this from the host’s terminal.
From your main Fedora VM’s terminal, run the
ip acommand inside the container:podman exec my-comparison-container ip aNote its IP address. It is also on a separate container network.
Now, run the
uname -rcommand inside the container:podman exec my-comparison-container uname -r
4.3 Step 3: Compare the Results
- Compare the output of
uname -rfrom your host Fedora VM with the output from the container. They will be identical. - Now, compare the output of
uname -rfrom your host with the output from the traditional VM. They will likely be different.
This proves the core concept: the container is just an isolated process sharing the host’s kernel, while the VM is a fully separate machine running its own, independent kernel.
4.4 Step 4: Clean Up
Stop the container you started for this exercise.
podman stop my-comparison-container5 Reflect and Review
Now that you have completed this exercise, reflect on your experience in your Microsoft Teams Student Notebook:
- 3
uname -routputs you observed (host, VM, container). - 2 commands you used to inspect the environments.
- 1 question you still have about container networking.
Answer these questions in your notebook to solidify your understanding:
- What is the purpose of the
podman execcommand? - What was the key difference you observed between the VM and the container?
- If you updated the kernel on your host Fedora VM, would the kernel inside the container change? What about the kernel inside the traditional VM? Why?
- Both the VM and the container had their own IP addresses. How does this provide network isolation?