0N/Alxc: linux Container library 0N/A(C) Copyright IBM Corp. 2007, 2008 0N/AThis library is free software; you can redistribute it and/or 0N/Amodify it under the terms of the GNU Lesser General Public 0N/ALicense as published by the Free Software Foundation; either 0N/Aversion 2.1 of the License, or (at your option) any later version. 0N/AThis library is distributed in the hope that it will be useful, 0N/Abut WITHOUT ANY WARRANTY; without even the implied warranty of 0N/AMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0N/ALesser General Public License for more details. 0N/AYou should have received a copy of the GNU Lesser General Public 2362N/ALicense along with this library; if not, write to the Free Software 2362N/AFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 0N/A<!ENTITY seealso SYSTEM "@builddir@/see_also.sgml">
0N/A <
date>@LXC_GENERATE_DATE@</
date>
0N/A <
refentrytitle>lxc</
refentrytitle>
0N/A <
manvolnum>7</
manvolnum>
0N/A Version @PACKAGE_VERSION@
0N/A <
refname>lxc</
refname>
0N/A <
title>Quick start</
title>
0N/A You are in a hurry, and you don't want to read this man page. Ok,
0N/A without warranty, here are the commands to launch a shell inside
0N/A a container with a predefined configuration template, it may
0N/A <
command>@BINDIR@/lxc-execute -n foo -f
0N/A @DOCDIR@/examples/lxc-macvlan.conf /
bin/
bash</
command>
0N/A <
title>Overview</
title>
0N/A The container technology is actively being pushed into the
0N/A mainstream linux kernel. It provides the resource management
0N/A through the control groups aka process containers and resource
0N/A isolation through the namespaces.
The linux containers, <
command>lxc</
command>, aims to use these
new functionalities to provide an userspace container object
which provides full resource isolation and resource control for
an applications or a system.
The first objective of this project is to make the life easier
for the kernel developers involved in the containers project and
features. The <
command>lxc</
command> is small enough to easily
manage a container with simple command lines and complete enough
to be used for other purposes.
<
title>Requirements</
title>
The <
command>lxc</
command> relies on a set of functionalities
provided by the kernel which needs to be active. Depending of
the missing functionalities the <
command>lxc</
command> will
work with a restricted number of functionalities or will simply
The following list gives the kernel features to be enabled in
the kernel to have the full features container:
-> Namespace cgroup subsystem
-> Freezer cgroup subsystem
-> Simple CPU accounting cgroup subsystem
-> Memory resource controllers for Control Groups
-> Basis for grouping tasks (Control Groups)
-> Support multiple instances of devpts
-> Virtual ethernet pair device
-> 802.1d Ethernet Bridging
-> File POSIX Capabilities
The kernel version >= 2.6.27 shipped with the distros, will
work with <
command>lxc</
command>, this one will have less
functionalities but enough to be interesting.
With the kernel 2.6.29, <
command>lxc</
command> is fully
The helper script <
command>lxc-checkconfig</
command> will give
you information about your kernel configuration.
Before using the <
command>lxc</
command>, your system should be
configured with the file capabilities, otherwise you will need
to run the <
command>lxc</
command> commands as root.
The control group can be mounted anywhere, eg:
<
command>mount -t cgroup cgroup /cgroup</
command>.
If you want to dedicate a specific cgroup mount point
for <
command>lxc</
command>, that is to have different cgroups
mounted at different places with different options but
let <
command>lxc</
command> to use one location, you can bind
the mount point with the <
option>lxc</
option> name, eg:
<
command>mount -t cgroup lxc /cgroup4lxc</
command> or
<
command>mount -t cgroup -ons,cpuset,freezer,devices
lxc /cgroup4lxc</
command>
<
title>Functional specification</
title>
A container is an object isolating some resources of the host,
for the application or system running in it.
The application / system will be launched inside a
container specified by a configuration that is either
initially created or passed as parameter of the starting commands.
<
para>How to run an application in a container ?</
para>
Before running an application, you should know what are the
resources you want to isolate. The default configuration is to
isolate the pids, the sysv ipc and the mount points. If you want
to run a simple shell inside a container, a basic configuration
is needed, especially if you want to share the rootfs. If you
want to run an application like <
command>sshd</
command>, you
should provide a new network stack and a new hostname. If you
want to avoid conflicts with some files
remount <
filename>/
var/
run</
filename> with an empty
directory. If you want to avoid the conflicts in all the cases,
you can specify a rootfs for the container. The rootfs can be a
directory tree, previously bind mounted with the initial rootfs,
so you can still use your distro but with your
own <
filename>/etc</
filename> and <
filename>/home</
filename>
Here is an example of directory tree
for <
command>sshd</
command>:
[root@lxc sshd]$ tree -d rootfs
and the mount points file associated with it:
[root@lxc sshd]$ cat fstab
<
para>How to run a system in a container ?</
para>
<
para>Running a system inside a container is paradoxically easier
than running an application. Why ? Because you don't have to care
about the resources to be isolated, everything need to be
isolated, the other resources are specified as being isolated but
without configuration because the container will set them
up. eg. the ipv4 address will be setup by the system container
init scripts. Here is an example of the mount points file:
[root@lxc debian]$ cat fstab
More information can be added to the container to facilitate the
configuration. For example, make accessible from the container
<
title>Container life cycle</
title>
When the container is created, it contains the configuration
information. When a process is launched, the container will be
starting and running. When the last process running inside the
container exits, the container is stopped.
In case of failure when the container is initialized, it will
pass through the aborting state.
| STOPPED |<--------------- | RUNNING | | ABORTING | | <
title>Configuration</
title>
<
para>The container is configured through a configuration
file, the format of the configuration file is described in
<
refentrytitle><
filename>
lxc.conf</
filename></
refentrytitle>
<
title>Creating / Destroying container
(persistent container)</
title>
A persistent container object can be
created via the <
command>lxc-create</
command>
command. It takes a container name as parameter and
optional configuration file and template.
The name is used by the different
commands to refer to this
container. The <
command>lxc-destroy</
command> command will
destroy the container object.
<
title>Volatile container</
title>
<
para>It is not mandatory to create a container object
The container can be directly started with a
configuration file as parameter.
<
title>Starting / Stopping container</
title>
<
para>When the container has been created, it is ready to run an
This is the purpose of the <
command>lxc-execute</
command> and
<
command>lxc-start</
command> commands.
If the container was not created before
starting the application, the container will use the
configuration file passed as parameter to the command,
and if there is no such parameter either, then
it will use a default isolation.
If the application is ended, the container will be stopped also,
but if needed the <
command>lxc-stop</
command> command can
be used to kill the still running application.
Running an application inside a container is not exactly the
same thing as running a system. For this reason, there are two
different commands to run an application into a container:
lxc-execute -n foo [-f config] /
bin/
bash lxc-start -n foo [-f config] [/
bin/
bash]
<
command>lxc-execute</
command> command will run the
specified command into the container via an intermediate
process, <
command>lxc-init</
command>.
This lxc-init after launching the specified command,
will wait for its end and all other reparented processes.
(that allows to support daemons in the container).
container, <
command>lxc-init</
command> has the pid 1 and the
first process of the application has the pid 2.
<
command>lxc-start</
command> command will run directly the specified
command into the container.
The pid of the first process is 1. If no command is
specified <
command>lxc-start</
command> will
To summarize, <
command>lxc-execute</
command> is for running
an application and <
command>lxc-start</
command> is better suited for
If the application is no longer responding, is inaccessible or is
not able to finish by itself, a
wild <
command>lxc-stop</
command> command will kill all the
processes in the container without pity.
<
title>Connect to an available tty</
title>
If the container is configured with the ttys, it is possible
to access it through them. It is up to the container to
provide a set of available tty to be used by the following
command. When the tty is lost, it is possible to reconnect it
<
title>Freeze / Unfreeze container</
title>
Sometime, it is useful to stop all the processes belonging to
a container, eg. for job scheduling. The commands:
will put all the processes in an uninteruptible state and
This feature is enabled if the cgroup freezer is enabled in the
<
title>Getting information about container</
title>
<
para>When there are a lot of containers, it is hard to follow
what has been created or destroyed, what is running or what are
the pids running into a specific container. For this reason, the
following commands may be usefull:
<
command>lxc-ls</
command> lists the containers of the
system. The command is a script built on top
of <
command>ls</
command>, so it accepts the options of the ls
will display the containers list in one column or:
will display the containers list and their permissions.
<
command>lxc-ps</
command> will display the pids for a specific
container. Like <
command>lxc-ls</
command>, <
command>lxc-ps</
command>
is built on top of <
command>ps</
command> and accepts the same
<
programlisting>lxc-ps --name foo --forest</
programlisting>
will display the processes hierarchy for the processes
belonging the 'foo' container.
<
programlisting>lxc-ps --lxc</
programlisting>
will display all the containers and their processes.
<
command>lxc-info</
command> gives informations for a specific
container, at present time, only the state of the container is
Here is an example on how the combination of these commands
allow to list all the containers and retrieve their state.
for i in $(lxc-ls -1); do
And displaying all the pids of all the containers:
for i in $(lxc-ls -1); do
lxc-ps --name $i --forest
<
command>lxc-netstat</
command> display network information for
a specific container. This command is built on top of
the <
command>netstat</
command> command and will accept its
The following command will display the socket informations for
<
title>Monitoring container</
title>
<
para>It is sometime useful to track the states of a container,
for example to monitor it or just to wait for a specific
<
command>lxc-monitor</
command> command will monitor one or
several containers. The parameter of this command accept a
regular expression for example:
will monitor the states of containers named 'foo' and 'bar', and:
will monitor all the containers.
For a container 'foo' starting, doing some work and exiting,
the output will be in the form:
'foo' changed state to [STARTING]
'foo' changed state to [RUNNING]
'foo' changed state to [STOPPING]
'foo' changed state to [STOPPED]
<
command>lxc-wait</
command> command will wait for a specific
state change and exit. This is useful for scripting to
synchronize the launch of a container or the end. The
parameter is an ORed combination of different states. The
following example shows how to wait for a container if he went
# launch lxc-wait in background lxc-wait -n foo -s STOPPED & # this command goes in background lxc-execute -n foo mydaemon & # block until the lxc-wait exits # and lxc-wait exits when the container <
title>Setting the control group for container</
title>
<
para>The container is tied with the control groups, when a
container is started a control group is created and associated
with it. The control group properties can be read and modified
when the container is running by using the lxc-cgroup command.
<
command>lxc-cgroup</
command> command is used to set or get a
control group subsystem which is associated with a
container. The subsystem name is handled by the user, the
command won't do any syntax checking on the subsystem name, if
the subsystem name does not exists, the command will fail.
will display the content of this subsystem.
will set the subsystem to the specified value.
<
para>The <
command>lxc</
command> is still in development, so the
command syntax and the API can change. The version 1.0.0 will be
the frozen version.</
para>
<
para>Daniel Lezcano <
email>daniel.lezcano@free.fr</
email></
para>
<!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:2 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:nil sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: -->