Saturday 5 June 2021

How to create lxc container on Ubuntu 18.04

If you are playing around with Linux, t is the best practice to do it on a virtual machine rather than your main Linux server. 

One popular option for sandboxing and an less known alternative to virtualbox is lxc, which is a purely text based container, native to Linux. 

Intstall it on Ubuntu 18.04 like this:

    sudo apt update

    sudo apt install openssh-server

Then you can:

    apt-get install lxc

In newer versions of lxc you also need to get containders sepeately

    apt install lxc-templates


Now you can create a container:

    lxc-create -t ubuntu -n newcon

Start the container

lxc-start -d -n newcon

Notice that by default username and password of the container sudoer are both: ubuntu

Find the container IP address:

ssh ubuntu@`sudo lxc-info -iH -n newcon`

10.0.3.147

Now you can connect to the container:

ssh ubuntu@10.0.3.147


Enjoy playing in the safe playground.