Install LXC under Debian. LXC Container management.
--- a/lxc.rst Sat Sep 03 11:54:41 2016 +0300
+++ b/lxc.rst Sat Sep 03 16:24:17 2016 +0300
@@ -6,6 +6,38 @@
.. contents::
:local:
+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``::
+
+ USE_LXC_BRIDGE="true"
+
+ LXC_ADDR="192.168.99.1"
+ LXC_NETMASK="255.255.255.0"
+ LXC_NETWORK="192.168.99.1/24"
+ LXC_DHCP_RANGE="192.168.99.100,192.168.99.200"
+ LXC_DHCP_MAX="20"
+
+and start service::
+
+ $ sudo service lxc-net start
+
+Check installation with::
+
+ $ sudo lxc-checkconfig
+
Create new container in LXC
===========================
@@ -15,3 +47,79 @@
$ 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 = 192.168.99.12/24
+ lxc.network.ipv4.gateway = 192.168.99.1
+
+Fix DNS resolution in container::
+
+ $ echo nameserver 8.8.8.8 | 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
+