LXD Bits and Tips

Credit: PeteLinforth / 2994 images

If you’re new to LXD (who isn’t?), the usage and interaction are a little bit different than LXC. Aside from command line differences, there’s quite a bit to learn to enable adequate troubleshooting and instance management.

Important Directories


This is an obviously important directory. On it’s face, it doesn’t need much explanation, however it should be noted there are some interesting tidbits in here. While /var/log/lxd/lxd.log covers the operation of the lxd daemon itself, there are child directories for each instance. In particular, lxc.conf can provide useful insight into how a container was configured.


This directory houses lots of important files.

lxd.db: An SQLite database. This likely holds lxd config variables, and possibly information about instances.

containers/<instance>/rootfs: This is the root file system of an instance.

images: Holds images and associated manifest-data.

security: Apparmor profiles and some other data.

There are a handful of other directories and files that are more or less self-explanatory as well.

Important Commands

Running lxc help will show you most of the commands. Some particularly useful commands are outlined here.

lxc config show <instance> --expanded

This shows import configuration data about an instance that is not readily available elsewhere. Most importantly, configured cgroup variables that affect instance resource availability.

lxc exec <instance> sh

If you’re familiar with the lxc-attach command, that is not present for lxd instances. The best way to replicate this function is to exec sh.

lxc file <command> <instance>

Directly push/pull/edit files on an instance.

lxc image …

Image manipulation. Much easier to add your own images to LXD than it is to LXC; no manual editing of complicated bash scripts in an obscure directory to get images from somewhere other than the default location. You can create your own tarball (tutorial coming soon!) to upload to LXD and easily create new instances with it. You can use lxc help image for more command usage information.


Under the hood, LXD and LXC use network namespaces to isolate tenant networking. There may come a time when you need to interact directly with the namespace for some reason.

If you are familiar with the command ip netns exec then this section will be useful to you. By default, the network namespaces aren’t given a name when created by LXC/LXD. At least not a name that the iproute2 commands can identify with ip netns list. However, you can see an assortment of network namespaces are indeed in use (if you have instances running) by running ip netns list-id. You can label/name these existing namespaces in the following manner:

pid=$(lxc info instance-0000000d | grep Pid | awk ‘{print $2}’)
mkdir -p /var/run/netns
ln -sf /proc/$pid/ns/net /var/run/netns/$pid

The above codeblock was adapted from here: netns-lxc

Please share…

If you have any other useful commands / insights into LXD usage that you use on a regular basis, I’d love to hear about them!

Like what you read? Give Michael Gugino a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.