LXD

Jump to: navigation, search

Introduction:

LXD is a next generation system container manager. It offers a user experience similar to virtual machines but using Linux containers instead.

Linux containers are not the same things as application containers like you might see running in Docker, CRI-O, or on Kubernetes. The purpose of Linux containers is to provide an entire OS environment quickly without the overhead that comes with creating a VM.

While the older Linux container software (LXC) is available for OpenSUSE Leap, Tumbleweed, and SLE; documentation is sparse and up-to-date images are hard to find. LXD, while not a native application on OpenSUSE, provides an efficient framework for downloading images, setting up networking, and setting up storage that LXC doesn't provide.

Installation

Install LXD

sudo zypper in lxd

Until issue 1190416 is not fixed, "attr" must be manually installed

sudo zypper in attr

Add the lxd service to your user:

sudo usermod -aG lxd $USER

Then log out and back in or reboot.

Confirm that your user is in the lxd group:

groups

Start the LXD service: Use the YaST services option to enable & start the service, or:

# systemctl enable --now lxd

Initialize LXD: (after you confirmed that you are in the LXD group)

lxd init

Example output of the init command:

$ lxd 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]: 
Name of the storage backend to use (btrfs, ceph, dir, lvm) [default=btrfs]: 
Would you like to create a new btrfs subvolume under /var/snap/lxd/common/lxd? (yes/no) [default=yes]: 
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]: 10.10.1.1/23
Would you like LXD to NAT IPv4 traffic on your bridge? [default=yes]: 
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]: 

Using LXD

List all available images:

lxc image list images:

Start an OpenSUSE Leap 15.1 Container:

lxc launch images:opensuse/15.1 myleapcontainer

"myleapcontainer" is the name of the container

List all container:

lxc list

Enter a container:

lxc exec myleapcontainer bash

Create an OpenSUSE Leap container that allow nested containers:

lxc launch images:opensuse/15.1 myleapcontainer -c security.nesting=true

"nested containers" means that you can run Docker or another container manager inside of your container.

With LXD you can run any number of applications that may normally not be possible with OpenSUSE from any number of Linux distributions quickly and easily. Want to play with Arch's AUR system? Start an Arch container. Want to see how Gentoo works? Start a Gentoo container. Want to try something in Tumbleweed but afraid of messing up your system, try it in a Tumbleweed container. Want to learn Saltstack, Puppet, or Chef? Start up a bunch of containers and see how they work as if they were separate machines.