To start a container, use lxc-start -n CN. By default
lxc-start will execute /sbin/init
in the container. You can provide a different program to execute, plus
arguments, as further arguments to lxc-start:
sudo lxc-start -n container /sbin/init loglevel=debug
If you do not specify the -d (daemon) option, then you will see a
console (on the container's /dev/console, see
Consoles for more information) on the terminal. If
you specify the -d option, you will not see that console, and lxc-start
will immediately exit success - even if a later part of container startup
has failed. You can use lxc-wait or
lxc-monitor (see Monitoring container status ) to check on the success or failure of the
To obtain LXC debugging information, use -o filename -l debuglevel,
sudo lxc-start -o lxc.debug -l DEBUG -n container
Finally, you can specify configuration parameters inline using -s.
However, it is generally recommended to place them in the container's
configuration file instead. Likewise, an entirely alternate config
file can be specified with the -f option, but this is not
While lxc-start runs the container's
/sbin/init, lxc-execute uses a
minimal init program called lxc-init, which attempts to
mount /proc, /dev/mqueue, and
/dev/shm, executes the programs specified on the
command line, and waits for those to finish executing.
lxc-start is intended to be used for system containers,
while lxc-execute is intended for application
this article for more).
You can stop a container several ways. You can use shutdown,
poweroff and reboot while logged into
the container. To cleanly shut down a container externally (i.e. from the host), you can issue
the sudo lxc-shutdown -n CN command. This takes an optional
timeout value. If not specified, the command issues a SIGPWR signal to the
container and immediately returns. If the option is used, as in
sudo lxc-shutdown -n CN -t 10, then the command will wait the
specified number of seconds for the container to cleanly shut down. Then,
if the container is still running, it will kill it (and any running
applications). You can also immediately kill the container (without any
chance for applications to cleanly shut down) using
sudo lxc-stop -n CN. Finally,
lxc-kill can be used more generally to send any signal
number to the container's init.
While the container is shutting down, you can expect to see some (harmless)
error messages, as follows:
$ sudo poweroff
[sudo] password for ubuntu: =
Broadcast message from ubuntu@cn1
(/dev/lxc/console) at 18:17 ...
The system is going down for power off NOW!
* Asking all remaining processes to terminate...
* All processes ended within 1 seconds....
* Deconfiguring network interfaces...
* Deactivating swap...
umount: /run/lock: not mounted
umount: /dev/shm: not mounted
mount: / is busy
* Will now halt
A container can be frozen with sudo lxc-freeze -n CN. This
will block all its processes until the container is later unfrozen using
sudo lxc-unfreeze -n CN.