sudo snap install lxd
or
sudo apt install lxc
NOTE: The snap version will most likely be more up to date.
sudo apt install lxc-utils lxc-templates
lxc info
returns:
If this is your first time running LXD on this machine, you should also run: lxd init To start your first instance, try: lxc launch ubuntu:18.04
Before you can create an instance, you need to configure LXD.
lxd init
NOTE: This will prompt for how to configure it. Just take the defaults for now.
mkdir ~/.config/lxc
lxc.include = /etc/lxc/default.conf lxc.idmap = u 0 100000 65536 lxc.idmap = g 0 100000 65536
lxc-create -t download -n test
NOTE: The download option is used to display a list of all available images, allowing one to be selected.
NOTE: An error may be seen:
Setting up the GPG keyring ERROR: Unable to fetch GPG key from keyserver lxc-create: test: lxccontainer.c: create_run_template: 1626 Failed to create container from template lxc-create: test: tools/lxc_create.c: main: 319 Failed to create container test
Try using the following:
lxc-create -t download -n test -- --keyserver hkp://p80.pool.sks-keyservers.net:80
or
lxc-create -n test -t download -- --no-validate
returns:
Setting up the GPG keyring Downloading the image index --- DIST RELEASE ARCH VARIANT BUILD --- alpine 3.10 amd64 default 20210103_13:00 alpine 3.10 arm64 default 20210103_13:00 alpine 3.10 armhf default 20210103_13:00 alpine 3.10 i386 default 20210103_13:00 ... centos 8 amd64 default 20210103_07:41 centos 8 arm64 default 20210103_07:08 centos 8 ppc64el default 20210103_07:08 debian bullseye amd64 default 20210103_05:24 debian bullseye arm64 default 20210103_05:24 ... ubuntu trusty arm64 default 20210103_07:42 ubuntu trusty armhf default 20210103_07:42 ubuntu trusty i386 default 20210103_07:42 ubuntu trusty ppc64el default 20210103_07:42 ubuntu xenial amd64 default 20210103_07:42 ubuntu xenial arm64 default 20210103_07:43 ubuntu xenial armhf default 20210103_07:43 ...
In this example the following is chosen:
Distribution: ubuntu Release: xenial Architecture: amd64 Downloading the image index Downloading the rootfs Downloading the metadata The image cache is now ready Unpacking the rootfs --- You just created an Ubuntu xenial amd64 (20210103_07:42) container. To enable SSH, run: apt install openssh-server No default root or user password are set by LXC.
lxc-info -n test
returns:
Name: test
State: STOPPED
lxc-start -n test
NOTE: The following error may be seen:
lxc-start: test: lxccontainer.c: wait_on_daemonized_start: 851 Received container state "ABORTING" instead of "RUNNING" lxc-start: test: tools/lxc_start.c: main: 308 The container failed to start lxc-start: test: tools/lxc_start.c: main: 311 To get more details, run the container in foreground mode lxc-start: test: tools/lxc_start.c: main: 313 Additional information can be obtained by setting the --logfile and --logpriority options
By default, unprivileged users are not allowed to create any network device on the host. To fix:
peter veth lxcbr0 10
NOTE: This means that peter is allowed to create up to 10 veth devices connected to the lxcbr0 bridge.
lxc-info -n test
returns:
Name: test State: RUNNING PID: 793414 IP: 10.0.3.101 Link: veth1000_qkOr TX bytes: 1.96 KiB RX bytes: 11.54 KiB Total bytes: 13.49 KiB
NOTE: This shows it is running.
lxc-attach -n test
NOTE: Enter exit to exit the Container Shell, back to the host.
lxc-stop -n test
lxc-destroy -n test