by author

Linux Containers LXC/LXD. Container Management from WebUI.

Markus Buchholz
Geek Culture
Published in
5 min readJun 16, 2021

--

In following article I will depict basic concept of Linux containers LXC and focus on the practical side of the technology. You will see how to run and manage different Linux distributions on your host (Linux OS). Article has to be considered only as a introduction to LXC/LXD technology, which origin has in Canonical company. The idea of article is not to compare with other similar technologies like Docker, Virtual Machine or Kubernetes. The ideas is straightforward to present the possibilities which can be utilized (nice to know).

Before we start divide into details and run Linux container (LXC) it seems to be more reasonable to understand the main architecture of containers and idea which stay behind considering technology. First we need to take a look on below figure , where I depicted main architecture levels of VM, DXC and Docker. Beside all presented architectures accommodate the virtualization concept, the VM is a slightly different since the virtualization starts on the hardware level. The main component of the architecture is hypervisor, the process responsible for spin up the VMs and facilitates the resources (CPU, RAM, storage disks, network, etc) across running VMs.
Going further you can consider that the containers are enabled sharing of the kernel resources with the host (Linux OS). This concept is opposed to the one to one mapping between a virtual machine and its kernel. Hypervisor provides more granular control and allocation over common available resources. Arguably, the disadvantage of using the hypervisor is the fact of overhead and limited scalability.

LXC containers however can be considered as an separate application (ordinary Linux OS distribution) which is run on Host (Linux) OS. There is no emulation of hardware since the LXC container can use all the available hardware resources (can be limited also). Personally I use LXC containers (different Linux distributions) for running the same application in the network and stress performance . I can start or stop the LXC within few milliseconds. As I mentioned I am not going to compare the technologies since all of us has own preferences and developed applications have different architecture and usage, The outperformed feature (over Docker) is the LXC gives me a direct possibility to store the data within the container, use full capability of the network and frankly speaking the LXC is a standard isolated and fully configurable OS.
According to concept principles the LXD is lighter-visor the provides a way to build on top of its network REST APIs to fully automate the process of multiple container deployment and management.

by author

I following section you will be familiar about the set of basic commands to start you container with favorite Linux OS, All the command has been discussed on Stéphane Graber website. I will show you how to access container using SSH., Finally I will depict web application which allow you to managed container from using your favorite browser.

If your OS is Ubuntu so probably you do not install the LXD. However, just in case you can install software using following command:

sudo snap install lxd

After you install LXD, you will have to initialize the environment. I recommend you (your familiarization phase) to just press the ENTER when the new question pops up.

lxd init

Available containers you can run as a containers LXC are listed on the Linux Container Project, however you can check also the full list on your terminal. Run command:

lxc remote list

After running the command four areas where you can grab the image will appear: images, local (this is you machine), ubuntu and ubuntu-daily.
You can check each location by using the command:

lxc image list images:
lxc image list local:
lxc image list ubuntu:
lxc image list ubuntu-daily:

Let us assume that we run command for repository ubuntu where we found interesting for us image ubuntu 18.04 and after we run the same command but pointing this time to proper repository. This time we are interested in to install Debian 11. The installation (launching) of this two containers can be performed by following commands:

lxc launch ubuntu:18.04 myubuntu1804lxc launch images:debian/11 mydebian11

myubuntu1804 and mydebian11 are our own local names.

Now you can run command to verify your previous work:

lxc list

You should receive similar:

by author

As you can see your container are running but in order to access the terminal you should perform for specific container a command:

lxc exec myubunty1804 bash
or
lxc exec mydebian11 bash

Useful commands to start/stop, etc LXC:

lxc start myubunty1804
lxc stop myubunty1804 [--force] # --force if it doesn't want to stop
lxc restart myubunty1804 [--force]
lxc pause myubunty1804
lxc move CONTAINER_NAME NEW_NAME

Now, we will see how to access container using SSH. Please, follow below steps.
Run following commands to access you container using SSH.

(Host) Login to guest myubunty1804 container:

lxc exec myubunty1804 bash

(Guest) Add new remote user ‘myname’

adduser myname//add user to sudo groupsudo usermod -aG sudo myname

(Guest) Edit /etc/ssh/sshd_config file

nano /etc/ssh/sshd_config fileInside the file adjust the flag from "no" to "yes", as follows
PasswordAuthentication yes

(Guest) Restart the sshd daemon

systemctl restart sshd

(Guest) Check the IP

ip aor on HOST:hypersivisonlxc list

(Host) ssh to the guest machine using userid and password

ssh myname@guest_ip

The last thing I will display in this article is a possibility for LXC management from browser. In this short introduction I will describe shortly the tool LXDUI.
Check the link and be inspired how to install (very easy) and use.

by author

LXDUI is the tool which can easily support terminal to manage containers without typing commands. It allows you to search and manage each container separately. The tool exhausts all available terminal command available from terminal. It gives you clear overview about your container environment.The tools is really handy and I think should be used.
As you remember the section above we created two containers: myubunty1804 and mydebian11. Running Web manager on our machine we are allowed managing created containers.

From following tab you can control all relevant to (in this case) mydebian11 container features — the same or similar to Virtual Machine. Remember the container starts/stop within millisecond, like Docker.

by author

You have also access to folders in your container OS.

by author

Thank you for reading.

--

--