# LXD Containers 101

**URL:** <https://discussion.scottibyte.com/t/lxd-containers-101/85>\
**Category:** Uncategorized\
**Created:** [May 12, 2022, 10:50pm UTC](https://discussion.scottibyte.com/t/lxd-containers-101/85 "2022-05-12T22:50:36Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![scott](https://discussion.scottibyte.com/letter_avatar_proxy/v4/letter/s/3e96dc/32.png) [@scott](https://discussion.scottibyte.com/u/scott)\
**Post date:** [May 12, 2022, 10:50pm UTC](https://discussion.scottibyte.com/t/lxd-containers-101/85/1 "2022-05-12T22:50:36Z")

</div>

I have presented many other videos on the channel that discuss aspects of LXD containers and networking. This presentation focuses on how to install LXD from scratch and configure it.

I also show how to host LXD containers on your main LAN using a bridged ethernet device. I also show how to properly nest Docker inside of a LXD container.

LXD containers are leaner, faster and more efficient on memory and CPU resources than virtual machines by far.

_BIG GLARING WARNING: THIS GUIIDE DESCRIBES USING BRIDGING ON YOUR LXD HOST TO PRESENT LXD CONTAINERS TO YOUR LAN. DO NOT INSTALL DOCKER ON YOUR LXD HOST BECAUSE DOCKER NETWORKS CONFLICT WITH BRIDGING IN LXD. INSTEAD, INSTALL DOCKER INSIDE ONE OR MORE LXD CONTAINERS AS DESCRIBED IN THE VIDEO AND NOT AT THE HOST LEVEL WHERE YOU HAVE LXD INSTALLED._

I recommend an Ubuntu 20.04 server as your LXD host. To install LXD:

```auto
sudo apt install lxd

```

Add your user account to the lxd group (for example):

```auto
sudo usermod -aG lxd scott
newgrp lxd
groups

```

Initialize LXD to prepare it for use following the tutorial in the presentation:

```auto
sudo lxd init

```

![image](https://discussion.scottibyte.com/uploads/default/original/1X/c9afdf2ba699498503d971ef3760c33e93c9fd70.jpeg)

List running containers:

```auto
lxc list

```

Create and start a container on the lxd private network:

```auto
lxc launch ubuntu:20.04 example --profile default -c boot.autostart=true

```

Find your default network device:

```auto
ip route show

```

Edit your netplan file to create a network bridge device on your LXD host (your file name may differ):

```auto
sudo nano /etc/netplan.00-installer-config.yml

```

Replace the contents of your file with something like the following with your network device name and appropriate addresses:

```auto
network:
  version: 2
  renderer: networkd

  ethernets:
    ens3:
      dhcp4: false
      dhcp6: false

  bridges:
    bridge0:
      interfaces: [ens3]
      addresses: [172.16.5.1/16]
      gateway4: 172.16.0.1
      nameservers:
        addresses:
          - 1.1.1.1
          - 1.0.0.1
      parameters:
        stp: true
        forward-delay: 4
      dhcp4: no

```

Apply the new network configuration:

```auto
sudo netplan apply

```

Create a LXD profile to use the bridge:

```auto
lxc profile create mainlan
lxc profile device add mainlan eth0 nic nictype=bridged parent=bridge0

```

Launch a LXD container using the bridge to get an address on your LAN:

```auto
lxc launch ubuntu:20.04 test --profile default --profile mainlan -c boot.autostart=true -c security.nesting=true

```

Connect to your new LXD container:

```auto
lxc exec test bash

```

Add a user account and Install docker _INSIDE_ the new LXD container:

```auto
adduser scott
usermod -aG sudo scott

apt update && apt upgrade -y

curl -sSL https://get.docker.com | sh

usermod -aG docker scott
newgrp docker
groups

```

Log into your new container via ssh on your new user account. Note: You may need to uninstall and reinstall openssh-server:

```auto
apt remove --purge openssh-server
apt install openssh-server

```

On your new user account on the LXD instance, try out a docker container:

```auto
docker run -d --name=Whiteboard -p 8080:8080 rofl256/whiteboard

```

Go into a web browser and visit: [http://a.b.c.d:8080](http://a.b.c.d:8080) to access the whiteboard where a.b.c.d is the IP address of your LXD container in which you installed docker.

Pro Tip: If your docker container failed, because you forgot to add nesting to the host LXD container:

```auto
lxc config set test security.nesting true

```

If you want an alternative to adding your network bridge via netplan and your LXD host has a desktop GUI:

```auto
sudo apt install network-manager-gnome

```

Then, from a terminal, you can access the network connection editor GUI:

```auto
nm-connection-editor

```
