How to Manage Linux Containers using LXC
Last Updated :
01 Dec, 2022
LXC is a technology for creating light weighted containers on your system. This technology is able to run on more than one Linux host. It is just like its counterparts i.e the other hypervisors like KVM and Xen. Unlike complete virtualization, containerization does not provide the user with complete isolation but the amount of load that is exerted on the Host OS is considerably less.
In this article, we will see the Management of Linux containers with the help of LXC, the Linux distribution that will be used in Ubuntu.
Installing LXC on the system
Use the below command to install LXC on your system:
sudo apt-get install lxc
Unfortunately, the above command does not download all the templates, so we might run into an error named No such file or directory - bad template while creating the container. To make sure we have the templates installed run the below command:
sudo apt-get install lxc-templates
Creation, Listing, login, and stopping of the container:
Step 1: Creation
A new container can be created by using the below command, we will be creating a sample container named sample1 which will be based on an ubuntu template :
sudo lxc-create -t <name_of_template> -n <name_of_container>
This process takes a while because there are a lot of packages to be collected and the creation of a container is also time taking.
Step 2: Listing the container(s)
Use the below command to list the available containers on your system:
sudo lxc-ls
By default the user created is ubuntu and the password is also ubuntu.
To see the complete details about the container use the below command:
sudo lxc-info -n <name_of_container>
Step 3: Starting the container
To start the container use the following command:
sudo lxc-start -n <name_of_container>
or
sudo lxc-start -d -n <name_of_container> (To start the container in a detached mode)
To verify the running status of the container use the below command:
sudo lxc-info -n <name_of_container>
Step 4: Logging into the container
To log in to the container we take the help of the lxc-console command:
sudo lxc-console -n <name_of_container>
To stop the container use the below command:
sudo lxc-stop -n <name_of_container>
Verify it:
sudo lxc-info -n <name_of_container>
Step 5: Freezing and Unfreezing
With the help of the lxc-freeze command we can freeze the containers:
sudo lxc-freeze -n <name_of_container>
Confirm whether the container is stopped or not:
You can see the FROZEN state.
To unfreeze the frozen container use the below command:
sudo lxc-unfreeze -n <name_of_container>
Step 6: Cloning the container and its power off
Before we clone a container make sure to stop it using the command discussed above, then type the below command to make a clone of it. The name of our cloned container will be sample2.
Note: Earlier the command had lxc-clone instead of lxc-copy, lxc-clone is now deprecated.
sudo lxc-copy -n <old container> -N <new container>
-n ----> old name, -N----> new name
The clone of the container can also be seen along with the existing container.
Step 7: Powering off the container
To power off the container use the below command:
sudo poweroff
Verify it once the container is stopped:
Step 8: Take snapshots of a container and its deletion
To take a snapshot of a container use the lxc-snapshot command:
sudo lxc-snapshot -n <name_of_container>
To delete a container use the below command:
sudo lxc-destroy -n <name_of_container>
Management of LXC Containers using a web panel:
Some people find working with the command line a bit tedious, this method is just for them. By installing the web panel of LXC one can manage the containers with the help of GUI.
Note: For installing the web panel you must be a root user.
sudo su
wget http://lxc-webpanel.github.io/tools/install.sh -O - | bash
The user interface can be accessed at the Url: http:/your_ip_address:5000/ by using the user id and password which by default are admin and admin.
Go to the site and enter the details:
You have successfully entered the GUI panel, now you can maintain the containers from the web panel easily.
Similar Reads
How to create a container using Podman?
The emergence of Podman as a powerful engine for containers without daemons has presented a very good alternative to Docker. Always having your Podman installation up to date means that you will have the latest features, bug fixes, and security enhancements. This guide will take you through the step
3 min read
How to Safely Remove Containers with Podman
Podman is a container management tool that helps in creating, deleting, or managing containerized environments. It is daemonless, unlike Docker, and is considered a more secure alternative in some cases. It also supports rootless containers that allow us to run containers inside Podman without havin
3 min read
What's a Linux Container?
The Linux container includes one or more processes that are isolated from the rest of the system. All of the files required to run them are provided by a separate image, ensuring that Linux containers are portable and consistent as they go from development to testing and ultimately to production. Th
7 min read
How to Install Ubuntu Server Edition with LXD Containers?
Managing several types of isolated environments on a single host is made possible with Ubuntu Server Edition installed in LXD containers for the system requirement. The Ubuntu team developed and maintained all the LXD container systems by following the practical implementation. A hypervisor service
4 min read
How to Use Ansible for Docker Container Management
Containerization has become one of the foundations for realizing scalable, reliable, and efficient application deployments in modern DevOps practice. Docker, as a leading containerization platform, enables developers to package applications and all dependencies into containers for consistency across
9 min read
How to Monitor Containers with the Podman "ps" Command
In the realm of containerization, where applications are bundled into units, for deployment it's crucial to have insight into the operational status of these containers. The Podman 'ps command provides a perspective, on this landscape enabling you to oversee and control your active containers.Termin
4 min read
Docker - Container Linking
Docker is a set of platforms as a service (PaaS) products that use the Operating system level visualization to deliver software in packages called containers.There are times during the development of our application when we need two containers to be able to communicate with each other. It might be p
4 min read
How To Share Storage Between Containers In Kubernetes ?
Kubernetes, or K8s, is an open-sourced container orchestration technology that is used to automate the manual processes of deploying, managing, and scaling applications by the help of containers. Kubernetes uses a single container per pod, which is great for most stateless applications, but some app
7 min read
How to Restart Container in Kubernetes?
Kubernetes is a platform for container orchestration created to simplify application deployment, scaling, and administration. Suppose you have a big package of LEGO parts and you want to use them to make something very spectacular. But as your LEGO creation becomes larger, it becomes harder to organ
8 min read
How to Remove Docker Containers
Docker is a platform that provides a set of PaaS (Platform as a Service) products that help developers containerize applications, allowing them to run consistently across various supported environments. The core component of Docker is Docker Engine which consists of: Docker Daemon: The process respo
2 min read