The LXD tutorials of Simos

I am in the process of updating these tutorials as they are largely obsolete.
In each updated tutorial I am focusing on Incus.

Old post starts below:

In this post I keep an index of the tutorials I have written on LXD at https://blog.simos.info/

Introduction to LXD

  1. Online course about LXD containers
  2. Πως χρησιμοποιούμε περιέκτες LXD (LXD containers) στο Ubuntu και άλλες διανομές [in Greek]
  3. Trying out LXD containers on our Ubuntu
  4. Playing around with LXD containers (LXC) on Ubuntu

How to use LXD on xyz VPS or hosting service

  1. Trying out LXD containers on Ubuntu on DigitalOcean
  2. Trying out LXD containers on Ubuntu on DigitalOcean, with block storage
  3. How to install LXD containers on Ubuntu on Scaleway [see also next tutorial]
  4. How to run the stock Ubuntu Linux kernel on Scaleway using KEXEC and server tags
  5. How to install LXD/LXC containers on Ubuntu on cloudscale.ch
  6. A closer look at the new ARM64 Scaleway servers and LXD
  7. How to use Ubuntu and LXD on Alibaba Cloud
  8. How to set up LXD on Packet.net (baremetal servers)
  9. How to set up LXD on Civo (new UK VPS provider)
  10. A closer look at the new Hetzner cloud servers, by running LXD
  11. How to repartition a Hetzner VPS disk for ZFS on its own partition for LXD
  12. A closer look at AMD EPYC baremetal servers at packet.net (1/4)
  13. Booting up the AMD EPYC baremetal server at packet.net (2/4)
  14. Configuring LXD on the AMD EPYC baremetal server at packet.net (3/4)
  15. Benchmarking LXD on an AMD EPYC server at packet.net (4/4)

Using LXD

  1. How to initialize LXD again [HOT]
  2. How to migrate LXD from DEB/PPA package to Snap package
  3. How to set up multiple secure (SSL/TLS, Qualys SSL Labs A+) websites using LXD containers
  4. How to install neo4j in an LXD container on Ubuntu
  5. How to use lxc remote with the LXD snap
  6. How to make your LXD containers get IP addresses from your LAN using a bridge
  7. How to make your LXD containers get IP addresses from your LAN using macvlan
  8. How to use LXD instance types
  9. How to preconfigure LXD containers with cloud-init
  10. How to set the timezone in LXD containers
  11. How to use Sysdig and Falco with LXD containers
  12. How to install a Node.js app in a LXD container
  13. How to run Docker in a LXD container
  14. Installing retdec on Ubuntu [in an LXD container]
  15. How to try LXD 3.0 beta
  16. How to use LXD container hostnames on the host in Ubuntu 18.04
  17. A closer look at Minimal Ubuntu for LXD
  18. Configuring public IP addresses on cloud servers for LXD containers
  19. How to manage LXD from within one of its containers
  20. How to run Julia on Jupyter in a LXD container
  21. Setting up the ESP32 in LXD on Ubuntu
  22. Using Arduino IDE for the ESP32 in a LXD container
  23. How to know when a LXD container has finished starting up
  24. Using the LXD Kali container image
  25. How to use the LXD Proxy Device to map ports between the host and the containers
  26. How to add both a private and public network to LXD using cloud-init
  27. Testing CVE-2019-11043 (php-fpm security vulnerability) with LXD system containers
  28. How to setup Netdata in a LXD container for real-time monitoring
  29. How to use virtual machines in LXD

How to run GUI applications on LXD

  1. How to run graphics-accelerated GUI apps in LXD containers on your Ubuntu desktop
  2. How to run Wine (graphics-accelerated) in an LXD container on Ubuntu
  3. How to use the X2Go remote desktop with LXD containers
  4. How to run TeamViewer in LXD
  5. A closer look at Chrome OS using LXD to run Linux GUI apps (Project Crostini)
  6. How to easily run graphics-accelerated GUI apps in LXD containers on your Ubuntu desktop
  7. How to run HelloWorld in radare2 (installed from a snap package)
  8. Running Steam in a LXD system container

How to contribute to the development of LXD

  1. Installing the Go programming language in Ubuntu
  2. How to develop the LXD hypervisor – Part #1 (client side lxc)
  3. How to develop the LXD hypervisor – Part #2 (using multipass/KVM VM)
  4. Using distrobuilder to create container images for LXC and LXD
  5. How to create a minimal container image for LXC/LXD with distrobuilder

Tutorial ideas

  1. How to do network forwarding between the host and the containers. Use iptables. Use proxy device in lxd-2.21-next. DONE
  2. a (resumable) desktop session in the cloud A rewrite of the X2Go to focus on the desktop session. DONE
  3. Third tutorial on getting LAN IP addresses to the containers, using router static routes.
  4. Linode disk repartitioning for ZFS.
  5. Moving containers between pools (how to do with LXD 2 and LXD 3).
15 Likes

Very much appreciated!

Thanks!

I also take requests for tutorials. If you see something missing but would be useful to have, feel free to propose it.

2 Likes

OK, here goes. :slight_smile:

How to access containers from your network, without the bridging techniques covered in the other guides.

I think I’m asking for a guide to using iptables to forward incoming traffic to a port on a container. I’ve seen plenty of general guides for this, and old ones which talk about lxc, but something specific to this problem when using the latest lxd, would be great. Alternatively, have I missed this in the lxd docs or getting started guides?

Maybe this will help you…

https://github.com/jorgeluiztaioque/lxd-forward

1 Like

The current version of LXD is 2.21. There is a patch that was accepted at https://github.com/lxc/lxd/issues/2504
and should make it in LXD 2.22 (or is it 3.0?).
It adds the functionality of a new device, the proxy device that currently can do TCP forwarding (UDP planned for the future).

It looks like this,

lxc config device add xen1 proxy0 proxy listen=tcp:192.168.50.196:80 connect=tcp:10.0.10.88:80 bind=host 

Therefore, once the new version of LXD is released, I plan to write a post about the proxy device. Then add some backup info that UDP and Unix sockets are pending work, and people can use iptables for those cases.

@bmullan thanks for the https://github.com/jorgeluiztaioque/lxd-forward link. This makes it better for new users to be able to list, create, and delete iptables commands. I’ll add this as well.

1 Like

Thanks for your blog posts @simos! They are very interesting.

Thanks @angristan!

I have added a new post on how to run TeamViewer on LXD.
In this post we learn about lxc console. TeamViewer is a bit peculiar and unfamiliar of the LXD confinement. You get many errors, and lxc console looks like a good compromise to get it to run.
Here is the link, https://blog.simos.info/how-to-run-teamviewer-in-lxd/

A new tutorial on how to repartition the disk of a Hetzner VPS so that you make space for a partition to put ZFS in there for LXD,
https://blog.simos.info/how-to-repartition-a-hetzner-vps-disk-for-zfs-on-its-own-partition-for-lxd/

2 Likes

Added tutorial https://blog.simos.info/how-to-try-lxd-3-0-beta/

It is a gentle introduction on how to switch now to using LXD 3.0 beta, as provided by the snap package.
It takes the necessary time to explain some core snap concepts.
There is a troubleshooting section as well.

I do not know how bad it would be to downgrade from LXD 3.0 to LXD 2.0.

2 Likes

Added the post
https://blog.simos.info/a-closer-look-at-chrome-os-using-lxd-to-run-linux-gui-apps-project-crostini/

Chrome OS can now run Linux apps, and it uses a machine container to host a Linux distro.
In this post we see how these work, and how Google’s container looks like.

1 Like

Added a post on how to setup the host on Ubuntu 18.04 so that you can do

ping mycontainer.lxd

Added updated tutorial on how to run GUI applications in a LXD container.
This version uses LXD profiles, so it is a joy to setup the system to run GUI applications.

I have tested

  1. the host running either Ubuntu 16.04 or Ubuntu 18.04
  2. the containers running either 12.04, 14.04, 16.04 or 18.04.

Enjoy!

Added a tutorial on how to do the HelloWorld with radare2/Cutter.
radare2 is a reversing framework and Cutter is the GUI.
I use a LXD GUI container to compile Cutter and run from there.

Added a post on Minimal Ubuntu. These are container images that are smaller than the standard Ubuntu container images. They are about half the size of the standard images.

To use Minimal Ubuntu images in LXD,

  1. Add the following remote,

    lxc remote add --protocol simplestreams ubuntu-minimal https://cloud-images.ubuntu.com/minimal/releases/
    
  2. Launch images with Minimal Ubuntu like this:

    lxc launch ubuntu-minimal:18.04 mycontainer
    
  3. Just a reminder on how to launch the standard Ubuntu images,

    lxc launch ubuntu:18.04 mycontainer
    

Read the blog post to find the differences between the two.

4 Likes

Added tutorial on how to configure LXD so that the containers can get directly a public IP address each.
This tutorial uses macvlan and configures statically the IP address in the container.

An alternative would be to use a bridge.

Yet another alternative would be to use IP aliases on the host to grab the IP address, then iptables to redirect network connections to the appropriate container.

Added the following tutorial,

It talks about sharing the Unix socket of LXD into one of the containers of that LXD installation. In this way, it is possible to manage LXD from within a container. The sharing of LXD’s Unix socket is done using the proxy device for Unix socket <-> Unix socket proxying. Requires LXD 3.4 or newer (i.e. the LXD snap).

2 Likes

Added a tutorial on how to run a Jupyter Notebook for the Julia computer language, in a LXD container,

In terms of LXD, it shows how to create a proxy device for TCP. It also demonstrates the difference between listening to localhost and listening to 0.0.0.0.

Added two more tutorials on developing on a ESP32 board and having the whole development environment inside LXD containers.

In terms of LXD features, these tutorials demonstrate the use of the unix-char device to share the /dev/ttyUSB0 character device of the host to the container. There is nice hot-plugging going on, which means it’s easy to connect and disconnect the ESP32 without much trouble in the LXD container.

The first tutorial is about using the command-line ESP-IDE development environment in a LXD container,

The second tutorial is about setting the Android IDE in a LXD container,

It has been great going through the process. I wish to see some feedback to evaluate if it is interesting to continue doing such tutorials (compared to core LXD tutorials).

One thought on serial devices, it’s usually best to use /dev/serial/by-id/ rather than /dev/ttyUSBX as the former will remain stable over reboots when you have more than one USB serial device connected.