[ About | Licence | Contacts ]
Written by Oleksandr Gavenko (AKA gavenkoa), compiled on 2018-02-10 from rev 9e6ad6607a9e.


Install LXC under Debian

$ sudo apt-get install lxc

To make network bridge install supplement packages:

$ sudo apt-get install bridge-utils dnsmasq

To bootstrap Debian dostro into container install:

$ sudo apt-get install debootstrap

To bring up network bridge edir /etc/default/lxc-net:



and start service:

$ sudo service lxc-net start

Check installation with:

$ sudo lxc-checkconfig

Create new container in LXC

-t defines distro name, -n gives name for container for further referencing, -- allow pass options to template script, -r specifies Debian release:

$ sudo lxc-create -t debian -n debtest -- -r sid

In order to use another miror:

$ MIRROR=http://httpredir.debian.org/debian sudo lxc-create -t debian -n debtest -- -r sid

Getting help for template specific options:

$ /usr/share/lxc/templates/lxc-ubuntu -h
$ /usr/share/lxc/templates/lxc-debian -h
$ /usr/share/lxc/templates/lxc-alpine -h

Put veth network configuration into container config /var/lib/lxc/$NAME/config:

lxc.network.type = veth
lxc.network.flags = up
lxc.network.link = lxcbr0
lxc.network.veth.pair = veth-stretch
lxc.network.name = veth-stretch
lxc.network.ipv4 =
lxc.network.ipv4.gateway =

Fix DNS resolution in container:

$ echo nameserver | sudo tee /var/lib/lxc/$NAME/rootfs/etc/resolv.conf

LXC Container management

List available VMs:

$ sudo lxc-ls

Start VM:

$ sudo lxc-start -n $NAME

Safely stop VM (with honer of init system):

$ sudo lxc-halt -n $NAME

Urgently stop VM:

$ sudo lxc-stop -n $NAME

Mark container to start on boot in /var/lib/lxc/$NAME/config:

lxc.start.auto = 1

Link containers in non standard location to take them in account:

$ ln -s /opt/lxc/$NAME /var/lib/lxc/$NAME

Run command in rinning container:

$ sudo lxc-attach -n $NAME-get update

Making snapshot

See lxc-snapshot(1).

List of snapshots:

$ sudo lxc-snapshot --list
$ sudo lxc-snapshot -n $NAME --list

Make a snapshot:

$ sudo lcx-halt -n $NAME
$ sudo lcx-snapshot -n $NAME

Restore from snapshot:

$ sudo lcx-halt -n $NAME
$ sudo lcx-snapshot -n $NAME -r $SNAPNAME