Creating Containers

The system configuration is located at /etc/lxc/lxc.conf or ~/.config/lxc/lxc.conf for unprivileged containers.

This configuration file is used to set values such as default lookup paths and storage backend settings for LXC. It can be found in each container’s /sys/class/net directory.

The command below configures the LXC (Linux container) networks to create an interface for a Linux bridge and an unconsumed second interface to be used by each container.

For more information on linux containers with Ubuntu, visit the lxc server guide.

echo -e "lxc.network.name = veth0\nlxc.network.type = veth\nlxc.network.name = veth_link1"  | sudo tee -a /etc/lxc/default.conf

This next command will create an Ubuntu Xenial container named “cone”.

$ sudo lxc-create -t download -n cone -- --dist ubuntu --release xenial --arch amd64 --keyserver hkp://p80.pool.sks-keyservers.net:80

If successful, you’ll get an output similar to this:

root@localhost:~# You just created an Ubuntu xenial amd64 (20180625_07:42) container.

To enable SSH, run: apt install openssh-server
No default root or user password are set by LXC.

You can make another container “ctwo”.

$ sudo lxc-create -t download -n ctwo -- --dist ubuntu --release xenial --arch amd64 --keyserver hkp://p80.pool.sks-keyservers.net:80

Afterwards, you can list your containers:

$ sudo lxc-ls
root@localhost:~# cone ctwo

Here are some lxc container commands you may find useful:

sudo lxc-ls --fancy
sudo lxc-start --name u1 --daemon
sudo lxc-info --name u1
sudo lxc-stop --name u1
sudo lxc-destroy --name u1

Lets start the first container:

$ sudo lxc-start --name cone

Verify its running:

$ sudo lxc-ls --fancy
NAME STATE   AUTOSTART GROUPS IPV4 IPV6
cone RUNNING 0         -      -    -
ctwo STOPPED 0         -      -    -