This document provides a comprehensive guide on managing LXC (Linux Containers) using both the Command-Line Interface (CLI) and the LXC Web UI. It covers creating tech-stacked images, copying containers and images between remotes, managing storage pools, and performing backups and restores.
Tech-stacked images are pre-configured container images that include specific software stacks, libraries, and configurations tailored for a particular use case. Here’s how to create them:
Create a Base Container: Start by launching a base container using an existing image:
lxc launch images:ubuntu/22.04 pssb1aldevlxc
Install Required Software: Access the container and install the desired software stack:
lxc exec pssb1aldevlxc -- apt update
lxc exec pssb1aldevlxc -- apt install -y nginx mysql-server php-fpm
Configure the Environment: Customize the container as needed (e.g., configure services, add scripts, or modify configuration files).
Publish the Container as an Image: Once the container is fully configured, publish it as a reusable image:
lxc stop pssb1aldevlxc
lxc publish pssb1aldevlxc --alias=my-tech-stack-image
Verify the Image: Check if the image is available locally:
lxc image list
Push the Image to a Remote (Optional): If you want to share the image with other systems, push it to a remote server:
lxc image copy my-tech-stack-image remote: --copy-aliases
Launch a New Container:
pssb1aldevlxc001
).Access the Container:
apt update && apt install -y nginx mysql-server php-fpm
Publish the Image:
pssb1aldevlxc
) and provide an alias (e.g., tech-stacked-pssb-image
).Push to Remote:
To copy containers and images between local and remote systems:
lxc copy ps1adevlxc001 remote:my-container
lxc image copy my-image remote: --copy-aliases
Copy Containers:
Copy Images:
Storage pools in LXC manage disk space for containers and images.
List Existing Storage Pools:
lxc storage list
Create a New Storage Pool: Create a new storage pool (e.g., ZFS or DIR):
lxc storage create my-pool dir
Set Default Storage Pool: Set the default storage pool for new containers:
lxc profile device add default root disk path=/ pool=my-pool
Resize a Storage Pool: For ZFS pools, resize the underlying dataset:
zfs set quota=50G my-pool
Delete a Storage Pool: Remove a storage pool (ensure no containers are using it):
lxc storage delete my-pool
List Storage Pools:
Create a New Storage Pool:
dir
, zfs
), and configuration options.Set Default Storage Pool:
default
profile and set the root
device to the desired storage pool.Resize/Delete Storage Pools:
.tar.gz
FilesExporting containers as .tar.gz
files creates portable backups.
Stop the Container (Optional): Stopping the container ensures data consistency:
lxc stop ps1adevlxc002
Export the Container:
Export the container to a compressed .tar.gz
file:
lxc export ps1adevlxc002 ps1adevlxc002-backup.tar.gz
Import the Backup: To restore the container from the backup:
lxc import ps1adevlxc002-backup.tar.gz
Export a Container:
.tar.gz
) and download the backup.Import a Container:
.tar.gz
file.Snapshots are point-in-time copies of a container’s state.
Take a Snapshot: Create a snapshot of a container:
lxc snapshot ps1adevlxc002 ps1adevlxc002-ss01
List Snapshots: View all snapshots of a container:
lxc info ps1adevlxc002
Restore a Snapshot: Revert back the container to a specific snapshot:
lxc restore ps1adevlxc003 ps1adevlxc002-ss01
Export a Snapshot: Export a snapshot as a standalone container:
lxc copy ps1adevlxc002/ps1adevlxc002-ss01 ps1adevlxc003
Remove a snapshot when it’s no longer needed:
lxc delete ps1adevlxc002/ps1adevlxc002-ss01
Create a Snapshot:
Restore a Snapshot:
Export a Snapshot:
.tar.gz
file.Delete a Snapshot:
This documentation outlines the key operations for managing LXC containers using both the CLI and the LXC Web UI. By following these steps, you can efficiently manage your containerized infrastructure and ensure data integrity and availability.
For further details, refer to the official LXC documentation.