← Back to Course Index

Week 5 IconWeek 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:

  1. Create and manage System Containers using lxc command-line tools.
  2. Configure networking between multiple LXC containers.
  3. Deploy an Unprivileged LXC Container using the Proxmox GUI.
  4. 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

  1. Log in to your Ubuntu Server VM (SSH or Console).
  2. 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.

  1. 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
  2. The system will download the image and create the root filesystem.

Step 3: Start and Inspect

  1. Start the container: bash sudo lxc-start -n test-cnt
  2. Check its status: bash sudo lxc-ls --fancy
  3. Field Report:
    • State: [ RUNNING / STOPPED ]
    • IP Address: [ _____________________________ ]

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!

  1. Verify the environment: bash cat /etc/os-release ps aux

  2. Critical Thinking:

    • Run uname -a. Does it show the Container's kernel or the Host's kernel?
    • [ _________________________________________________________________________ ]
  3. 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

  1. Create cnt-A and cnt-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
  2. Start them: bash sudo lxc-start -n cnt-A sudo lxc-start -n cnt-B

Step 2: Test Connectivity

  1. Get IP of cnt-B: sudo lxc-ls --fancy
  2. Ping cnt-B from cnt-A: bash sudo lxc-attach -n cnt-A -- ping -c 3 <IP_OF_CNT_B>

  3. 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)

  1. In Proxmox GUI, go to Storage (local) -> CT Templates.
  2. Click Templates.
  3. Search for ubuntu-22.04-standard and Download.

Step 2: Deploy Container

  1. Click Create CT.
  2. General: Hostname: gui-container, Password: secure.
  3. Template: Select the Ubuntu template.
  4. Disks: 8GB.
  5. CPU/RAM: 1 Core, 512MB RAM.
  6. Network: Bridge vmbr0, DHCP.
  7. Finish.

Step 3: Hotplugging Resources

LXC allows changing limits on the fly (via Cgroups), unlike VMs which often need a reboot.

  1. Open the Console of your new container.
  2. Run free -m (Note the total RAM).
  3. In Proxmox Resources tab, increase RAM to 1024MB.
  4. Run free -m again immediately.
    • Observation: The RAM increased instantly!

Lab Checkpoint

Practical Skills Checklist

Reflection


← Back to Course Index