Week 5 - Lab 1: LXC System
Containers
Module: Operating Systems 3 (Virtualisation & Cloud Technologies)
Topic: System Containers (CLI vs GUI)
Estimated Time: 60 Minutes
Instructor: KT Nshimba
Lab Overview
In this lab, you will gain hands-on experience with System Containers. You will explore
them in two ways:
1. The "Hard" Way (CLI): Using standard lxc tools inside a Linux VM to
understand the underlying mechanics (Namespaces).
2. The "Easy" Way (GUI): Using Proxmox VE to deploy and manage containers with a few
clicks.
Objectives:
- Create and manage System Containers using
lxccommand-line tools. - Configure networking between multiple LXC containers.
- Deploy an Unprivileged LXC Container using the Proxmox GUI.
- Demonstrate "Hotplugging" of resources (RAM/CPU).
Prerequisites: - Your Ubuntu Server VM (from Week 2). - Your Proxmox VE Interface.
Part 1: Working with System Containers (LXC CLI)
In this section, you will use the standard Linux Container (LXC) tools to create a container. You will perform these steps inside your Ubuntu Server VM.
Step 1: Install LXC Tools
- Log in to your Ubuntu Server VM (SSH or Console).
- Install the LXC package:
bash sudo apt update sudo apt install -y lxc lxc-utils
Step 2: Create a Container
We will create a small Alpine Linux container.
- Run the creation command:
bash # Syntax: lxc-create -n <name> -t <template> -- <template-options> sudo lxc-create -n test-cnt -t download -- --dist alpine --release 3.19 --arch amd64 - The system will download the image and create the root filesystem.
Step 3: Start and Inspect
- Start the container:
bash sudo lxc-start -n test-cnt - Check its status:
bash sudo lxc-ls --fancy - Field Report:
- State:
[ RUNNING / STOPPED ] - IP Address:
[ _____________________________ ]
- State:
Step 4: Access the Container
Since this is a "System Container," you can log in just like a separate server.
1. Attach to the container's console:
bash
sudo lxc-attach -n test-cnt
* Notice the command prompt changes!
-
Verify the environment:
bash cat /etc/os-release ps aux -
Critical Thinking:
- Run
uname -a. Does it show the Container's kernel or the Host's kernel? [ _________________________________________________________________________ ]
- Run
-
Exit the container:
bash exit
Part 2: LXC Networking Scenario
Containers usually connect to a default bridge (lxcbr0) on the host.
Step 1: Create Two Containers
- Create
cnt-Aandcnt-B:bash sudo lxc-create -n cnt-A -t download -- --dist alpine --release 3.19 --arch amd64 sudo lxc-create -n cnt-B -t download -- --dist alpine --release 3.19 --arch amd64 - Start them:
bash sudo lxc-start -n cnt-A sudo lxc-start -n cnt-B
Step 2: Test Connectivity
- Get IP of cnt-B:
sudo lxc-ls --fancy -
Ping cnt-B from cnt-A:
bash sudo lxc-attach -n cnt-A -- ping -c 3 <IP_OF_CNT_B> -
Result: Did it ping?
[ Yes / No ]
Part 3: Proxmox LXC (The easy way)
Now that you understand the CLI mechanics, let's see how Proxmox automates this.
Step 1: Download a Template (GUI)
- In Proxmox GUI, go to Storage (local) -> CT Templates.
- Click Templates.
- Search for
ubuntu-22.04-standardand Download.
Step 2: Deploy Container
- Click Create CT.
- General: Hostname:
gui-container, Password:secure. - Template: Select the Ubuntu template.
- Disks: 8GB.
- CPU/RAM: 1 Core, 512MB RAM.
- Network: Bridge
vmbr0, DHCP. - Finish.
Step 3: Hotplugging Resources
LXC allows changing limits on the fly (via Cgroups), unlike VMs which often need a reboot.
- Open the Console of your new container.
- Run
free -m(Note the total RAM). - In Proxmox Resources tab, increase RAM to 1024MB.
- Run
free -magain immediately.- Observation: The RAM increased instantly!
Lab Checkpoint
Practical Skills Checklist
- Created containers via CLI
(
lxc-create) - Accessed container console
(
lxc-attach) - Created a container via Proxmox GUI
- Demonstrated resource hotplugging
Reflection
- Comparison: Which method (CLI vs GUI) gave you more control? Which was faster?
- Shared Kernel: Why did
uname -ainside the container show the same output as the host?