They “weight” between VMs and Application Containers (e.g. Docker) - VMs are heavier and Application Containers the lightest. LXC/LXD are the middle ground.
LXD is the CLI/REST API
“Machine containers” - A full operating system containerized.
Can have access to hardware on the containerized OS
VMs reserve memory for a VM on boot. On LXC, they use limits.memory and limits.cpu, by default all on the machine.
You can make clusters of LXD hosts (you can move a container from one host to another)
You can snapshot/restore containers
You can nest LXD (have LXD inside the containerized OS)
They use the LXD daemon host kernel
You can ping between 2 or more containers using their DNS name (which is container-name.lxd)
On Ubuntu:
sudo systemctl enable lxdlxd initlxc versionlxc remote list (list remote repositories)lxc image list (show local downloaded images)lxc image list images: (images on a repository)lxc image list images:deb (images on a repository)lxc image list images:cent (images on a repository)lxc launch ubuntu:20.04 (launch a container)lxc list (list containers)lxc delete <container>lxc stop <container>lxc start <container>lxc copy <container> <another-container> (create a new container from an existing one)lxc move <container> <new-name> (renames a container)lxc exec <container> bash (enter the container as root)lxc exec <container> su - <username> (enter the container as another user)lxc info <container> (info on running container)lxc config show <container> (container configuration - shows limits and other info)lxc profile listlxc profile show default (show the default profile)lxc profile copy default new-profile-name (copy default profile)lxc launch ubuntu:18.04 <container> --profile <profile-name> (create a new container with a custom profile)Restrict resources on container - uses cgroups - you can do that on profile or dinamically:
lxc config set <container> limits.memory 512MBlxc profile edit <profile-name>config: {} to:config:
limits.memory: 512MB
push files from host to the container: lxc file push <file> <container>/<path>
pull files from the container to host: lxc file pull <container>/<path> <file>
snapshot a container: lxc snapshot <container> <snapshot-name> (copies the entire filesystem)
restore container from snapshot: lxc restore <container> <snapshot-name> (copies the entire filesystem - lxc list shows how many snapshots are there for a container)
To use LXD nesting, you must set security.nesting and security.privileged:
lxc config set <container> security.privileged truelxc config set <container> security.nesting truelxc profile edit <profile-name>config: {} to:config:
security.privileged: true
security.nesting: true