When I first started learning LXD containers I got very confused on different things I was reading everywhere, it seemed like there was not so much material on lxd containers. What are LXD containers? How are they different from docker containers? What is the difference between LXD and LXC? Why would I even learn or use LXC?

LXD is a system container manager which is similar to virtual machines but using Linux containers instead. LXD containers are lightweight and they are open source as well.

In general LXD is a tool to manage Linux containers.

What are the differences between LXC and LXD?

Differences between lxd and lxc
Differences between lxd and lxc

Even if they sound as they would be the same LXD and LXC are different things.

LXC – is short for “Linux Container”. It’s job is to virtualize software on operating systems within the Linux Kernel. So it basically creates a virtual container almost like a Virtual Machine. I know that this sounds a lot like Docker but even if they have similarities they are very different.

LXD – Is an extension of LXC or better to say is a tool which connects to libxlc the library and LXC and gives users many more benefits to use containers. Lets say LXD is like a REST API written in GO programming language which creates a daemon that can be accessed by apps by using Unix sockets. It is possible to be accessed remotely via HTTPS as well.

So LXC together with LXD are very powerful, very rich in features, very lightweight and they are one of the best alternatives of Docker containers.

What are the differences between LXD containers and Docker?


The difference between LXD/LXC and docker is the type of the container.

Docker – is an application container which is using minimal resources. Docker containers use OS-level virtualization to create a package of software. They are isolated and each container works on its own with the installed libraries on it. They can communicate with each other through well-defined channels. 

LXD/LXC – containers are different types of container. They are not in application level like Docker instead they are in containers in operation system level. Which means LXD containers create a virtual linux operating system on it. You basically have a container which is like a virtual linux operating system. Within the container you install whatever you need for you application without affecting the host. 

Let’s say you need to make a specific application to work, you need to install a different version of linux. You may need to install different applications, databases, libraries or services but you don’t want to affect things you have in the host system. Since LXD container is like a virtual OS you can do all of these things.

Benefits of using LXD

  • Lightweight container
  • They use Linux Kernel
  • OS level container
  • High scalability 
  • Open-source
  • Network and storage management capabilities, such as storage pooling
  • Control over machine resources to be used by the containers.
  • You can do snapshots or clones on running containers.

Let’s get started with learning how to work with LXD

Let’s get started and learn the basics of how to work with LXD containers and the most used commands. Here I will explain the most used commands but to have a deep understanding of LXD/LXC containers refer to their documentation https://lxd.readthedocs.io/.

On ubuntu you have to install LXD via snap because the apt package isn’t updated and is using an older version of LXD.

sudo snap install lxd

To have permission to run LXD commands you have to add your user on lxd group

sudo usermod -G lxd -a <username>

First thing after you successfully installed LXD you need to initialize LXD environment:

lxd init

After you run this command you will get asked some questions on the terminal on how to configure LXD. Keep the default if you are just starting off.

You may have stored containers on different places on your system. To see where all containers are stored run:

 lxc storage list

Of course containers should have some source to be taken from. So you might want to see a list of all images where we can create our LXD container from:

lxc remote list

To see all available Operation System images from which you can create your local container run:

 lxc image list images

You can even see all images saved on your PC by using this command :

lxc image list

Here you can see a list of all different linux containers. So you have to go throw the list and find what operation system you need to create your container from. Yeah, I know the list is big but you can filter it if you know what are you looking for. Let’s say you want to find CentOS images for your container. You can just add something lie `:cent` into you command to filter the list like :

lxc image list images:cent

This will display only all images that have `cent` on their name like for example CentOS.

Chose the operating system you need and create container by using `lxc launch images:{alias} `name_of_new_container` for example:

 lxc launch images:centos/8 my_container

So like this you just created your first container on CentOS 8 and you called it my_container.

List all containers on your local machine by using :

lxc list

If you need to stop the container you can do so with the command:

lxc stop ‘name_of_your_container’

Start the container again by

lxc start ‘name_of_your_container’

If you need to delete the container

lxc delete `name_of_the_container`

Many times you wold need to copy the container and to use it for other applications

lxc copy `name_of_the_containet` `name_of_the_newContainer`

And of course, why do you need the container if you don’t know how to enter and install your applications on it. To login in your container use the LXD exec command for example:

lxc exec `name_of_container` bash