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:

Downloading a template and creating a container

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

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

In this example, we will use an archlinux image.

Note: Adjust the above options to your needs.

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

This means that the container has been created successfully.

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

Which will return:

Running a container

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

Obviously, n1 is the container we created earlier.

To see if it started, run:

Which will now return:

Attaching to a container

You can connect to the running container using the lxc-attach  command.

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:

For our example:

Destroying a container

If you want to completely destroy a container: