Install and Use LXC to manage containers in ubuntu 20.04

LXC is an operating-system-level virtualization method for running multiple isolated Linux systems on a control host using a single Linux kernel.

Install

sudo apt install -y lxc lxc-templates

check the LXC using the following command:

lxc-checkconfig

Create LXC Container

LXC comes with lots of ready-made templates. List them with

ls /usr/share/lxc/templates/

create your first container

sudo lxc-create --template download --name u1
lxc-create -n new-container -t ubuntu

This will interactively ask for a container root filesystem type to download – in particular the distribution, release, and architecture. To create the container non-interactively, you can specify these values on the command line:

sudo lxc-create -t download -n u1 -- --dist ubuntu --release DISTRO-SHORT-CODENAME --arch amd64
# or
sudo lxc-create -t download -n u1 -- -d ubuntu -r DISTRO-SHORT-CODENAME -a amd64

List containers:

lxc-ls

Start Container

lxc-start -n new-container -d

take a console of the container

lxc-console -n new-container

get the details of the running container

lxc-info -n new-container

start and stop the container

lxc-start -n new-container
lxc-stop -n new-container

Pause and Unpause the container

lxc-freeze -n new-container
lxc-unfreeze -n new-container

You can also take a snapshot of the container

# First stop the container
lxc-stop -n new-container

# take a snapshot of the container
lxc-snapshot -n new-container

# see the location of the snapshot
lxc-snapshot -L -n new-container

# You can restore the snapshot using
lxc-snapshot -r snap0 -n new-container

to delete the container

lxc-stop -n new-container
lxc-destroy -n new-container

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.

Install

wget https://lxc-webpanel.github.io/tools/install.sh -O - | bash

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.

Now, enter the default username admin and password admin, then click on the Log In button

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

wget https://lxc-webpanel.github.io/tools/update.sh -O - | bash
comments powered by Disqus
Citizix Ltd
Built with Hugo
Theme Stack designed by Jimmy