LXC containers quickstart guide – Ian's notes

LXC containers quickstart guide

October 21st, 2020 by

Install the LXC package:

sudo apt install -y lxc

Configure LXC:

mkdir ~/.config/lxc
cp /etc/lxc/default.conf ~/.config/lxc

cat /etc/subuid | grep "$(whoami):" | cut -f 2,3 -d : | sed 's/:/ /g' | sed 's/^/lxc.id_map = u 0 /' >> ~/.config/lxc/default.conf
cat /etc/subgid | grep "$(whoami):" | cut -f 2,3 -d : | sed 's/:/ /g' | sed 's/^/lxc.id_map = g 0 /' >> ~/.config/lxc/default.conf

Set up the network configuration:

$(echo "$(whoami) veth lxcbr0 10" >> /etc/lxc/lxc-usernet)

sudo modprobe veth
lsmod | grep veth

Create a container:

sudo lxc-create -t download -n <name>

Follow the prompts to select a distro. Start the container (-d is daemonise, -F is foreground):

sudo lxc-start -n <name> -d

To get info on the container:

sudo lxc-info -n <name>

Attach to the container as root:

sudo lxc-attach -n <name>

Or log in to the console:

sudo lxc-console -n <name>

And finally, to get the IP address of the container:

sudo lxc-info -n <name> -i -H