LXC is a user space interface for the Linux kernel containment features. Through a powerful API and simple tools, it lets Linux users easily create and manage system or application containers.
Creating an LXC in PVE is to download a template image. A template image is a preconfigured image of an operating system that can be used to create new LXC quickly.
The first step update container template database:
List available images:
Also filter the output:
pveam available --section system
The following command downloads a template image of an Ubuntu 22.04 operating system and saves it in the storage pool named "volume01":
pveam download volume01 vztmpl/ubuntu-22.04-standard_22.04-1_amd64.tar.zst
Listing Template Images
To see a list of all the template images stored in the storage pool named "volume01," use the following command:
pveam list volume01
Now that we have a template image, we can create a new LXC.
pct create 403 volume01:vztmpl/ubuntu-22.04-standard_22.04-1_amd64.tar.zst \ --storage volume01 --rootfs volume=volume01:16 \ --ostype ubuntu --arch amd64 --password P@ssw0rd --unprivileged 1 \ --cores 2 --memory 1024 --swap 0 \ --hostname lxc-ubuntu \ --net0 name=eth0,bridge=vmbr0,ip=dhcp,firewall=1,type=veth \ --start true
Configuring the LXC
|creates a new LXC with ID 403 and the image from the storage "volume01.|
|specifies the storage pool to be used for storing the LXC's disks.|
|specify the operating system and architecture of the LXC.|
|set the root password for the LXC and enable unprivileged mode.|
|specify the number of CPU cores, amount of memory and swap space allocated to the LXC.|
|This option sets the hostname of the LXC to "lxc-ubuntu".|
|the interface name set to eth0 and bridge to vmbr0 from the host, enable firewall and the network type value is: veth.|
|This option starts the LXC after it has been created.|
This type of network interface allows the LXC (container) or virtual machine to communicate with other devices on the network as if it were a physical device on the network. The veth interface also allows for network isolation between different LXC or virtual machines running on the same host system.
Enter the container:
pct enter 403
Update the system:
apt update && apt upgrade
Install some packages:
apt install -y curl git tmuxvim
Set Vim as default editor:
update-alternatives --set editor /usr/bin/vim.basic
useradd -m user -s /bin/bash
Switch to user:
su - user
Stop the LXC
pct stop 401
Destroying an LXC
To remove an LXC from the system, use the following command:
pct destroy 401 --purge
This command destroys the LXC with ID 401 and removes its configuration files from the system.
Removing a Template Image
If you want to remove a template image from the storage pool, use the following command:
pveam remove volume01:vztmpl/vztmpl/ubuntu-22.04-standard_22.04-1_amd64.tar.zst
We covered the basics of managing LXC in Proxmox Virtual Environment (PVE).
Looked at how to download a template image, create an LXC, and configure it with various options. We also saw how to remove an LXC from the system.
PVE offers many more commands and options for managing LXCs, and we encourage you to explore them further to get the most out of this powerful virtualization platform.