August 09 2016, 00:00#

LXC on Debian 8

LXC (Linux Containers) is an operating-system-level virtualization method for running multiple isolated Linux systems (containers) on a control host using a single Linux kernel.

We will see how to quickly setting up a container.

Prerequisites

We need a network bridge br0. If needed, take a look on my post about that: "Setting up a network bridge on Debian 7".

Installation

# apt install lxc
# mkdir -p {/srv/lxc,/etc/lxc/auto}
# chmod 750 /srv/lxc

Creating a container

Copy the desired template and edit it.

# cp /usr/share/doc/lxc/examples/lxc-veth.conf /srv/lxc/example.conf

Configuration example

# Container with network virtualized using a pre-configured bridge named br0 and
# veth pair virtual network devices
lxc.utsname = example
lxc.network.type = veth
lxc.network.flags = up
lxc.network.link = br0
lxc.network.hwaddr = 
lxc.network.ipv4 = 10.0.0.3/24
lxc.network.ipv4.gateway = 10.0.0.1

# Autostart
lxc.start.auto = 1
lxc.start.delay = 30

Creating a Debian container

The root password must be defined at the end of the creation process.

# lxc-create -n example -f /srv/lxc/example.conf --dir /srv/lxc/example -t debian

If we want to start automatically our container at boot, we have to link the configuration file into the /etc/lxc/auto directory.

# ln -s /var/lib/lxc/example/config /etc/lxc/auto/example

Network configuration

Edit /srv/lxc/example/etc/network/interfaces

To disable DHCP, comment iface eth0 inet dhcp.

auto lo
iface lo inet loopback

auto eth0
#iface eth0 inet dhcp

Informations about a container

# lxc-info -n example

Start

Normal mode

# lxc-start -n example

Daemon mode

# lxc-start -dn example

Console

Useful when the container run in the daemon mode

# lxc-console -n example

Stop

# lxc-stop -n example

Destroy

# lxc-destroy -n example

Tags : unix linux debian containerization virtualization