What are LXCs?

Containers are a lightweight virtualization technology. They are more akin to an enhanced chroot than to full virtualization like Qemu or VMware, both because they do not emulate hardware and because containers share the same operating system as the host.

Installing lxc

First of all, you have to install lxc and its dependencies. So, go ahead and issue the following command:

sudo apt-get install lxc

Downloading a template and creating a container

The next step, after installing lxc, is to download the template you want and create the container:

sudo lxc-create -t download -n n1

After executing the above command, the system will list the available templates and interactively ask you to choose among the options of Distribution,

Sponsored
Release and Architecture.

In this example, we will use an archlinux image.

Distribution: archlinux
Release: current
Architecture: amd64

Note: Adjust the above options to your needs.

Once the operation is finished, you’ll see the following message:

You just created an ArchLinux container (release=current, arch=amd64, variant=default)

For security reason, container images ship without user accounts
and without a root password.

Use lxc-attach or chroot directly into the rootfs to set a root password
or create user accounts.

This means that the container has been created successfully.

You can verify that the container is created by issuing the following command:

sudo lxc-ls --fancy

Which will return:

NAME STATE   AUTOSTART GROUPS IPV4 IPV6 
n1   STOPPED 0         -      -    -

Running a container

To run the created container, you have to execute the following command:

sudo lxc-start -n n1 -d

Obviously, n1 is the container we created earlier.

Sponsored

To see if it started, run:

sudo lxc-ls --fancy

Which will now return:

NAME STATE   AUTOSTART GROUPS IPV4       IPV6 
n1   RUNNING 0         -      10.0.3.119 -

Attaching to a container

You can connect to the running container using the

lxc-attach

  command.

sudo lxc-attach -n n1

You will be then logged in as root to the newly created container.

Stopping a container

You can stop a container with the following command:

sudo lxc-stop -n <container name>

For our example:

sudo lxc-stop -n n1

Destroying a container

If you want to completely destroy a container:

sudo lxc-destory -n <container name>

 

The post Setting up Linux Containers (LXC) appeared first on NixPal.

Ubuntu Server Admin

Recent Posts

Canonical Releases Ubuntu 25.04 Plucky Puffin

The latest interim release of Ubuntu introduces “devpacks” for popular frameworks like Spring, along with…

2 days ago

Ubuntu 25.04 (Plucky Puffin) Released

Ubuntu 25.04, codenamed “Plucky Puffin”, is here. This release continues Ubuntu’s proud tradition of integrating…

2 days ago

Extended Security Maintenance for Ubuntu 20.04 (Focal Fossa) begins May 29, 2025

Ubuntu released its 20.04 (Focal Fossa) release 5 years ago, on March 23, 2020. As…

3 days ago

Ubuntu 20.04 LTS End Of Life – activate ESM to keep your fleet of devices secure and operational

Focal Fossa will reach the End of Standard Support in May 2025, also known as…

4 days ago

Ubuntu MATE 25.04 Release Notes

Ubuntu MATE 25.04 is ready to soar! 🪽 Celebrating our 10th anniversary as an official…

4 days ago

Ubuntu Weekly Newsletter Issue 887

Welcome to the Ubuntu Weekly Newsletter, Issue 887 for the week of April 6 –…

5 days ago