Linux

Linux containers: How to install LXC/LXD for container management

LINUX-CONTAINERS-1

You can’t talk about this without making reference to Canonical, the company behind ubuntu. This is because Canonical built upon the architecture of LXC for LXD, It will shock you to know that Docker is also built upon the technology of LXC but that will be a story for another day. But you have to understand that Docker is a lightweight and uncomplicated container runtime that enables users to create only one application process per Docker container, as you read along you will understand the differences. So, you might also be wondering ah! why do I want to use LXC or LXD in 2021 or maybe you are even reading this article in 2023 and beyond

LXC (LinuX Containers) is an operating system level virtualization technology that enables the creation and execution of multiple isolated Linux Virtual Environments (VE) on a single control host.

Why use LXD

Linux is used by 96.3 percent of the world’s top 1 million servers. Only 1.9 percent of the rest use Windows, with 1.8 percent using FreeBSD. LXD allows you to isolate not only apps but also the complete operating system so as to have all the features of Linux. Its support scripts specialize in transforming containers to lightweight computers, or servers that load faster and use less RAM. LXD is a next-generation system container and virtual machine manager. It offers a unified user experience around full Linux systems running inside containers or virtual machines.

LXD is network aware, and all interactions are handled via a simple REST API, allowing you to interact with containers on remote systems remotely, copying and moving them as needed. Do you want to go all out? LXD also includes clustering capabilities, allowing you to combine dozens of servers into a single LXD server.

The crucial advantage of LXD is that it is an extension of LXC, thus it can handle most LXC functionalities as well as advanced features. LXD’s capabilities have indeed been enhanced thanks to the use of REST APIs.

Some other guides can be found here how-to-configure-user-resource-limits-and-restrictions-in-linux/, practical-use-of-selinux-in-production-how-to-locate-directory-file-context-and-restore-it-with-selinux/, how-to-create-and-deliver-a-report-on-system-utilization-on-a-linux-based-os/ ,demos-that-can-help-you-become-a-better-kubernetes-administrator/ , how-to-use-container-insights-to-get-the-full-benefits-of-azure-monitor-for-azure-kubernetes-workload/

Installation

Now that I have been able to make you see why having a container that can run a complete Linux operating system is important, let get our virtual machines ready. I shall be using Ubuntu 16.04 installed on VM Workstation pro for the task in this article

Let’s run an apt-update on the system before we proceed and run the command

apt install lxd lxd-client
aptlsd
apt install lxd

 LXD’s own CLI tool is actually named ‘lxc’ (LX Client). The original’s LXC cli is actually starting with ‘lxc-’. our installation command installs the CLI as well.

LXC  provides the basic functionality used under the hood by LXD. However, it should not be confused with the lxc CLI client tool provided by LXD.

The LXD client lxc is a command tool to manage your LXD servers.

We need to make LXD ready for container and images

sudo lxd init
lxd-init
lxd init

while configuring there were a lot of options we were asked to make, I choose yes for all and entered the given port and for the password, I just hit enter indicating a blank keyboard. An example of one of the options from the lxd init command is shown below

pkg
lxd config

The last step of the installation process for LXD is adding the user to lxd group. In this case of the task we are working on, I am the user

sudo usermod -aG lxd raphael
group
usermod

Before we proceed, let us see how we are doing with this command, It might take a while but let’s be patient

lxc list
lxc-list
lxd list

lxc list shows you what containers are running on your host. At the moment we do have not any image downloaded so it’s empty. So let us do something about this with this command below, we choose to call the name of the image techdirectarchive.

Make you run systemctl restart lxd if not you might get image creation error with the message certificate signed by an unknown authority

sudo lxc launch ubuntu:16.04 techdirectarchive
techdirectarchive
lxd launch ubuntu
techdirectarchive2
container running
lxd launch ubuntu:16.04
LXC
comic-hyena container

If you don’t specify a name, it will automatically create it for you as you can see from the above screenshot we didn’t choose comic-hyena as the preferred name in the launch command

lxc-list
lxd list running containers

if we do an lxc list we can see that the containers we created are in the running state

If we run the command below we will see that we be logged into the container

#lxc exec techdirectarchive -- /bin/bash

we can exit this container by typing exit on the terminal

techdirect-1

Did you notice what is in the screenshot?, you have been given the full powers of the computer, so as the container you are not restricted in anyway at all. we can do the same for the second container called comic-hyena

#lxc exec comic-hyena -- /bin/bash
comic-hyena
lxc exec comic-hyena

Lets stop the container comic-hyena with the command below and see the state with lxc list

#lxc stop comic-hyena
lxc-stop-comic-hyena
lxc stop

If we do the same for techdirectarchive container we will see that both containers are no longer running

lxc-stop-techdirectarchive
all containers stopped

Summary

Linux containers LXD allows you to isolate not only apps but also the complete operating system so as to have all the features of Linux. we saw this when we ran the command #lxc exec comic-hyena — /bin/bash. The container itself became root. sudo apt install lxd lxd-client will enable you to install it. You start with LXD init and accept all defaults. You can create a container with the command #lxc launch <image> : version.

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x