How to Install and Configure LXC Container on Ubuntu 16.04

By Hitesh Jethva, Alibaba Cloud Tech Share Author. Tech Share is Alibaba Cloud’s incentive program to encourage the sharing of technical knowledge and best practices within the cloud community.

LXC also known as a Linux Containers is a free, open source, lightweight and operating system-level virtualization software that allows us to run a multiple isolated Linux systems on a single Linux host. LXC provides the cgroups functionality that allows the limitation of resources like, CPU, memory, network without the need for starting any virtual machines. You can start Linux container without using the separate kernel using LXC. LXC allows you to run multiple instances of an operating system or application on a single host, without inducing overhead on CPU and memory. Containers can be used to quickly set up a virtual environment for testing/QA purposes.

Features:

  1. Lightweight and resource friendly.
  2. Rapid and easy deployment.
  3. Run multiple versions of an operating system on a single server.
  4. Comprehensive process and resource isolation.

In this tutorial, we will explain how to set up LXC container on Alibaba Cloud Elastic Compute Service (ECS) with Ubuntu 16.04.

Requirements

  1. A fresh Alibaba Cloud Ubuntu 16.04 instance with minimum 2GB of RAM.
  2. A static IP address is configured.
  3. A Root password is set up on the server.

Launch Alibaba Cloud ECS Instance

First, log in to your Alibaba Cloud ECS Console. Create a new ECS instance, choosing Ubuntu 16.04 as the operating system with at least 2GB RAM. Connect to your ECS instance and log in as the root user.

Once you are logged into your Ubuntu 16.04 instance, run the following command to update your base system with the latest available packages.

Install LXC

By default, LXC is available in the Ubuntu 16.04 default repository. You can install it by running the following command:

After installing LXC, you can check the LXC using the following command:

If everything fine, you should see the following output:

Create LXC Container

LXC comes with lots of ready-made templates for creating Linux containers. You can list out them by running the following command:

Output:

Now, create your first Ubuntu container with the following command:

Once the container created succesfully, you should see the following output:

You should see that the Ubuntu container created with the default user ubuntu and password ubuntu.

You can now list the created container with the following command:

Output:

Start Container

Ubuntu container is now created. You can now start the container with the following command:

Next, take a console of the container by running the following command:

You will be asked to provide username and password to log in. Provide the username ubuntu and password ubuntu to log in. You should see the following output after login:

You can exit from the container any time by pressing “Ctrl+a” followed by “q”

Working with LXC Container

You can get the details of the running container using the following command:

Output:

You can start and stop the container with the following command:

You can Pause and Unpause the container with the following command:

You can also take a snapshot of the container. First, stop the running container with the following command:

Next, take a snapshot of the container with the following command:

Output:

You can see the location of the snapshot using the following command:

Output:

You can restore the snapshot using the following command:

If you want to delete the container, run the following command:

Install LXC Web Panel

LXC Web Panel is a GUI management tool to manage Linux containers. You can create, start, stop, clone, delete and restart Linux container from the web browser using LXC web panel.

You can install the LXC web panel to your system by running the following command:

This command will download and install LXC web panel automatically to your system:

Once the installation is completed, open your web browser and type the URL http://your-server-ip:5000. You will be redirected to the LXC login page as shown below:

Image for post
Image for post

Now, enter the default username admin and password admin, then click on the Log In button. You should see the LXC web panel in the following page:

Image for post
Image for post

You can update the LXC web panel using the following command:

Congratulations! You have successfully installed LXC and LXC web panel to your system. You can now easily create and manage Linux container from the central location.

Related Alibaba Cloud Products

Alibaba Cloud IoT Platform allows IoT companies stable communication between devices and the IoT Platform. Featuring nodes deployed globally, devices around the world can communicate with the IoT platform rapidly and with low latency. Alibaba Cloud IoT Platform also provides various security measures that guarantee individual device security as well as secure communication between devices and the IoT platform.

Apsara Stack enables enterprises to improve utilization of their existing on-premises data center as well as install innovative services in security, and meet requirements in data sovereignty and compliance. Apsara Stack supports hyperscale cluster systems containing more than 6,000 servers per region to meet the requirements of operating large business systems and applications visited by a high number of users. Users can efficiently operate and manage those resources, applications, and data on the Apsara Stack platform through a unified management portal, which supports multi-tenancy mode.

Reference:https://www.alibabacloud.com/blog/how-to-install-and-configure-lxc-container-on-ubuntu-16-04_594090?spm=a2c41.12183794.0.0

Written by

Follow me to keep abreast with the latest technology news, industry insights, and developer trends.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store