LXC is a lightweight Virtualization technology that is used to run multiple isolated virtual units often referred to as containers in a chroot environment on a single host using a single Linux kernel.
Some common terminologies used with LXC include:
- chroot – Chroot also referred to as change root or change root jail is a section in the file system which is isolated from the rest of the file system. A program executed in this environment cannot access files outside the designated directory tree.
- cgroups – This is a Kernel feature that allows aggregating or partitioning tasks (processes) and all their children into hierarchically organized groups to isolate resources.
Installing LXC on Ubuntu
LXC can easily be installed on Ubuntu from upstream repositories using the following commands:
$ sudo apt install lxc
The above command will install lxc package and all dependencies required then configure a default container network. The name of the bridge is lxcbr0:
# ip ad | grep lxc 3: lxcbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000 inet 10.0.3.1/24 scope global lxcbr0
Using LXC on Ubuntu
You can use LXC in two modes:
- Privileged – This is when you run lxc commands as root user.
- Unprivileged – This is when you run commands as a non-root user.
Below is an example of essential commands to create an LXC container.
# lxc-create -t download -n mylxc-ubuntu -- --dist ubuntu --release xenial --arch amd64
-n for the name of the container and -t for a template. Once the container has been created, it is nor started by default. You can list all lxc containers using:
To start the container, run:
# lxc-start -n <container-name>
Install LXC Web UI on Ubuntu
There are a number of tools that you can use to manage your LXC containers. On this article, we’ll install and use LXC Web Panel. Run this command to install it:
# wget https://lxc-webpanel.github.io/tools/install.sh -O - | bash
This will automatically install and configure LXC Web UI for you. You’ll get an output similar to below after installation.
Installtion complete! Adding /etc/init.d/lwp... Done Starting server...done. Connect you on http://your-ip-address:5000/
As you can see, the service is listening on port 5000. If you have a firewall, open the port so that you can access it from a remote device.
$ sudo ufw allow 5000
You can now open the URL http://your-ip-address:5000/ on your browser to access the dashboard.
Login with user admin and password admin
Don’t forget to change the password after logging in.