The linux containers (lxc) are always created before being used. This creation defines a set of system resources to be virtualized / isolated when a process is using the container. By default, the pids, sysv ipc and mount points are virtualized and isolated. The other system resources are shared across containers, until they are explicitly defined in the configuration file. For example, if there is no network configuration, the network will be shared between the creator of the container and the container itself, but if the network is specified, a new network stack is created for the container and the container can no longer use the network of its ancestor.
The configuration file defines the different system resources to be assigned for the container. At present, the utsname, the network, the mount points, the root file system and the control groups are supported.
Each option in the configuration file has the form key = value fitting in one line. The '#' character means the line is a comment.
Allows to set the architecture for the container. For example, set a 32bits architecture for a container running 32bits binaries on a 64bits host. That fix the container scripts which rely on the architecture to do some work like downloading the packages.
Valid options are x86, i686, x86_64, amd64
The utsname section defines the hostname to be set for the container. That means the container can set its own hostname without changing the one from the system. That makes the hostname private for the container.
The network section defines how the network is virtualized in the container. The network virtualization acts at layer two. In order to use the network virtualization, parameters must be specified to define the network interfaces of the container. Several virtual interfaces can be assigned and used in a container even if the system has only one physical network interface.
empty: will create only the loopback interface.
veth: a peer network device is created with one side assigned to the container and the other side is attached to a bridge specified by the lxc.network.link. If the bridge is not specified, then the veth pair device will be created but not attached to any bridge. Otherwise, the bridge has to be setup before on the system, lxc won't handle any configuration outside of the container. By default lxc choose a name for the network device belonging to the outside of the container, this name is handled by lxc, but if you wish to handle this name yourself, you can tell lxc to set a specific name with the lxc.network.veth.pair option.
vlan: a vlan interface is linked with the interface specified by the lxc.network.link and assigned to the container. The vlan identifier is specified with the option lxc.network.vlan.id.
macvlan: a macvlan interface is linked with the interface specified by the lxc.network.link and assigned to the container. lxc.network.macvlan.mode specifies the mode the macvlan will use to communicate between different macvlan on the same upper device. The accepted modes are private, the device never communicates with any other device on the same upper_dev (default), vepa, the new Virtual Ethernet Port Aggregator (VEPA) mode, it assumes that the adjacent bridge returns all frames where both source and destination are local to the macvlan port, i.e. the bridge is set up as a reflective relay. Broadcast frames coming in from the upper_dev get flooded to all macvlan interfaces in VEPA mode, local frames are not delivered locallay, or bridge, it provides the behavior of a simple bridge between different macvlan interfaces on the same port. Frames from one interface to another one get delivered directly and are not sent out externally. Broadcast frames get flooded to all other bridge ports and to the external interface, but when they come back from a reflective relay, we don't deliver them again. Since we know all the MAC addresses, the macvlan bridge mode does not require learning or STP like the bridge module does.
phys: an already existing interface specified by the lxc.network.link is assigned to the container.
up: activates the interface.
For stricter isolation the container can have its own private instance of the pseudo tty.
If the container is configured with a root filesystem and the inittab file is setup to use the console, you may want to specify where goes the output of this console.
If the container is configured with a root filesystem and the inittab file is setup to launch a getty on the ttys. This option will specify the number of ttys to be available for the container. The number of getty in the inittab file of the container should not be greater than the number of ttys specified in this configuration file, otherwise the excess getty sessions will die and respawn indefinitly giving annoying messages on the console.
The mount points section specifies the different places to be mounted. These mount points will be private to the container and won't be visible by the processes running outside of the container. This is useful to mount /etc, /var or /home for examples.
The root file system of the container can be different than that of the host system.
The control group section contains the configuration for the different subsystem. lxc does not check the correctness of the subsystem name. This has the disadvantage of not detecting configuration errors until the container is started, but has the advantage of permitting any future subsystem.
The capabilities can be dropped in the container if this one is run as root.
In addition to the few examples given below, you will find some other examples of configuration file in /usr/share/doc/lxc/examples
This configuration sets up a container to use a veth pair device with one side plugged to a bridge br0 (which has been configured before on the system by the administrator). The virtual network device visible in the container is renamed to eth0.
lxc.utsname = myhostname lxc.network.type = veth lxc.network.flags = up lxc.network.link = br0 lxc.network.name = eth0 lxc.network.hwaddr = 4a:49:43:49:79:bf lxc.network.ipv4 = 220.127.116.11/24 18.104.22.168 lxc.network.ipv6 = 2003:db8:1:0:214:1234:fe0b:3597
This configuration will setup several control groups for the application, cpuset.cpus restricts usage of the defined cpu, cpus.share prioritize the control group, devices.allow makes usable the specified devices.
lxc.cgroup.cpuset.cpus = 0,1 lxc.cgroup.cpu.shares = 1234 lxc.cgroup.devices.deny = a lxc.cgroup.devices.allow = c 1:3 rw lxc.cgroup.devices.allow = b 8:0 rw
This example show a complex configuration making a complex network stack, using the control groups, setting a new hostname, mounting some locations and a changing root file system.
lxc.utsname = complex lxc.network.type = veth lxc.network.flags = up lxc.network.link = br0 lxc.network.hwaddr = 4a:49:43:49:79:bf lxc.network.ipv4 = 22.214.171.124/24 126.96.36.199 lxc.network.ipv6 = 2003:db8:1:0:214:1234:fe0b:3597 lxc.network.ipv6 = 2003:db8:1:0:214:5432:feab:3588 lxc.network.type = macvlan lxc.network.flags = up lxc.network.link = eth0 lxc.network.hwaddr = 4a:49:43:49:79:bd lxc.network.ipv4 = 188.8.131.52/24 lxc.network.ipv4 = 192.168.10.125/24 lxc.network.ipv6 = 2003:db8:1:0:214:1234:fe0b:3596 lxc.network.type = phys lxc.network.flags = up lxc.network.link = dummy0 lxc.network.hwaddr = 4a:49:43:49:79:ff lxc.network.ipv4 = 184.108.40.206/24 lxc.network.ipv6 = 2003:db8:1:0:214:1234:fe0b:3297 lxc.cgroup.cpuset.cpus = 0,1 lxc.cgroup.cpu.shares = 1234 lxc.cgroup.devices.deny = a lxc.cgroup.devices.allow = c 1:3 rw lxc.cgroup.devices.allow = b 8:0 rw lxc.mount = /etc/fstab.complex lxc.mount.entry = /lib /root/myrootfs/lib none ro,bind 0 0 lxc.rootfs = /mnt/rootfs.complex lxc.cap.drop = sys_module mknod setuid net_raw lxc.cap.drop = mac_override
chroot(1), pivot_root(8), fstab(5)
lxc(1), lxc-create(1), lxc-destroy(1), lxc-start(1), lxc-stop(1), lxc-execute(1), lxc-kill(1), lxc-console(1), lxc-monitor(1), lxc-wait(1), lxc-cgroup(1), lxc-ls(1), lxc-ps(1), lxc-info(1), lxc-freeze(1), lxc-unfreeze(1), lxc.conf(5)
Daniel Lezcano <email@example.com>