#LXC Containers
Linux Containers - the original container technology.
#Overview
LXC provides OS-level virtualization, running full Linux systems in containers.
| Feature | Description |
|---|---|
| Full OS | Complete Linux distro |
| Shared kernel | Same as host |
| Persistent | Like a lightweight VM |
#LXC vs Docker
| Feature | LXC | Docker |
|---|---|---|
| Purpose | System containers | App containers |
| Init system | Full (systemd) | Single process |
| Use case | Development VMs | Microservices |
#Basic Commands
bash
1# Install LXC
2sudo apt install lxc
3
4# List available images
5lxc-ls
6
7# Create container
8sudo lxc-create -t download -n mycontainer -- -d ubuntu -r jammy -a amd64
9
10# Start container
11sudo lxc-start -n mycontainer
12
13# Attach to container
14sudo lxc-attach -n mycontainer
15
16# Stop container
17sudo lxc-stop -n mycontainer
18
19# Destroy container
20sudo lxc-destroy -n mycontainer#LXD (Modern LXC)
bash
1# Install LXD
2sudo snap install lxd
3
4# Initialize
5lxd init
6
7# Launch container
8lxc launch ubuntu:22.04 mycontainer
9
10# Execute command
11lxc exec mycontainer -- apt update
12
13# Shell access
14lxc exec mycontainer -- bash[!TIP] Pro Tip: LXC/LXD is excellent for development environments that need full OS!