I haven't found what the exact differences are between LXC and LXD containers. It seems that you can see LXD as an evolution of LXC, with better tooling and security. For what it's worth, I use LXC in my Proxmox environment as it is available out-of-the-box. On AWS I use LXD.
Install snap daemon
sudo apt update && sudo apt install snapd
Install LXD as snap
sudo snap install lxd
Add user to lxd
group
sudo usermod -aG lxd jodibooks
Initialize lxd
lxc init
Would you like to use LXD clustering? (yes/no) [default=no]:
Do you want to configure a new storage pool? (yes/no) [default=yes]:
Name of the new storage pool [default=default]: lxc-storage
Name of the storage backend to use (btrfs, dir, lvm) [default=btrfs]: dir
Create a new BTRFS pool? (yes/no) [default=yes]:
Would you like to use an existing block device? (yes/no) [default=no]:
Size in GB of the new loop device (1GB minimum) [default=15GB]: 8GB
Would you like to connect to a MAAS server? (yes/no) [default=no]:
Would you like to create a new local network bridge? (yes/no) [default=yes]:
What should the new bridge be called? [default=lxdbr0]:
What IPv4 address should be used? (CIDR subnet notation, “auto” or “none”) [default=auto]:
What IPv6 address should be used? (CIDR subnet notation, “auto” or “none”) [default=auto]:
Would you like LXD to be available over the network? (yes/no) [default=no]:
Would you like stale cached images to be updated automatically? (yes/no) [default=yes]
Would you like a YAML "lxd init" preseed to be printed? (yes/no) [default=no]:
Create containers (see LXC Commands)
Migrate to latest version
sudo lxd.migrate
For example, move WordPress data into the WordPress LXD container examplesalon
. User and group www-data
inside the container are mapped onto id 1000033
in the host from which we copy the data. If you don't change ownership, all copied files and directories will be owned by nobody:nogroup
inside the container, and this cannot be changed from within.
sudo -i
cp -r /home/ubuntu/html /var/snap/lxd/common/lxd/storage-pools/default/containers/examplesalon/rootfs/var/www
chown -R 1000033:10000033 /var/snap/lxd/common/lxd/storage-pools/default/containers/examplesalon/rootfs/var/www/html
rm -r /home/ubuntu/html
exit
Or use rsync
with option --numeric-ids
(untested, found here: https://discuss.linuxcontainers.org/t/user-nobody-and-group-nogroup-after-the-migration-of-the-containers/6273/7)
sudo -i
rsync --numeric-ids --archive --delete-after /home/ubuntu/html /var/snap/lxd/common/lxd/storage-pools/default/containers/examplesalon/rootfs/var/www
rm -r /home/ubuntu/html
exit
lxc launch ubuntu:18.04 examplesalon
lxc copy demosalon examplesalon
lxc delete examplesalon
lxc start examplesalon
lxc stop examplesalon
lxc exec examplesalon -- sudo --user ubuntu --login
lxc list