]> git.proxmox.com Git - mirror_lxc.git/blob - doc/lxc.container.conf.sgml.in
Merge pull request #1839 from hallyn/2017-10-02/oci
[mirror_lxc.git] / doc / lxc.container.conf.sgml.in
1 <!--
2
3 lxc: linux Container library
4
5 (C) Copyright IBM Corp. 2007, 2008
6
7 Authors:
8 Daniel Lezcano <daniel.lezcano at free.fr>
9
10 This library is free software; you can redistribute it and/or
11 modify it under the terms of the GNU Lesser General Public
12 License as published by the Free Software Foundation; either
13 version 2.1 of the License, or (at your option) any later version.
14
15 This library is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
19
20 You should have received a copy of the GNU Lesser General Public
21 License along with this library; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23
24 -->
25
26 <!DOCTYPE refentry PUBLIC @docdtd@ [
27
28 <!ENTITY seealso SYSTEM "@builddir@/see_also.sgml">
29 ]>
30
31 <refentry>
32
33 <docinfo><date>@LXC_GENERATE_DATE@</date></docinfo>
34
35 <refmeta>
36 <refentrytitle>lxc.container.conf</refentrytitle>
37 <manvolnum>5</manvolnum>
38 </refmeta>
39
40 <refnamediv>
41 <refname>lxc.container.conf</refname>
42
43 <refpurpose>
44 LXC container configuration file
45 </refpurpose>
46 </refnamediv>
47
48 <refsect1>
49 <title>Description</title>
50
51 <para>
52 LXC is the well-known and heavily tested low-level Linux container
53 runtime. It is in active development since 2008 and has proven itself in
54 critical production environments world-wide. Some of its core contributors
55 are the same people that helped to implement various well-known
56 containerization features inside the Linux kernel.
57 </para>
58
59 <para>
60 LXC's main focus is system containers. That is, containers which offer an
61 environment as close as possible as the one you'd get from a VM but
62 without the overhead that comes with running a separate kernel and
63 simulating all the hardware.
64 </para>
65
66 <para>
67 This is achieved through a combination of kernel security features such as
68 namespaces, mandatory access control and control groups.
69 </para>
70
71 <para>
72 LXC has supports unprivileged containers. Unprivileged containers are
73 containers that are run without any privilege. This requires support for
74 user namespaces in the kernel that the container is run on. LXC was the
75 first runtime to support unprivileged containers after user namespaces
76 were merged into the mainline kernel.
77 </para>
78
79 <para>
80 In essence, user namespaces isolate given sets of UIDs and GIDs. This is
81 achieved by establishing a mapping between a range of UIDs and GIDs on the
82 host to a different (unprivileged) range of UIDs and GIDs in the
83 container. The kernel will translate this mapping in such a way that
84 inside the container all UIDs and GIDs appear as you would expect from the
85 host whereas on the host these UIDs and GIDs are in fact unprivileged. For
86 example, a process running as UID and GID 0 inside the container might
87 appear as UID and GID 100000 on the host. The implementation and working
88 details can be gathered from the corresponding user namespace man page.
89 UID and GID mappings can be defined with the <option>lxc.idmap</option>
90 key.
91 </para>
92
93 <para>
94 Linux containers are defined with a simple configuration file. Each
95 option in the configuration file has the form <command>key =
96 value</command> fitting in one line. The "#" character means the line is a
97 comment. List options, like capabilities and cgroups options, can be used
98 with no value to clear any previously defined values of that option.
99 </para>
100
101 <para>
102 LXC namespaces configuration keys by using single dots. This means complex
103 configuration keys such as <option>lxc.net.0</option> expose various
104 subkeys such as <option>lxc.net.0.type</option>,
105 <option>lxc.net.0.link</option>, <option>lxc.net.0.ipv6.address</option>, and
106 others for even more fine-grained configuration.
107 </para>
108
109 <refsect2>
110 <title>Configuration</title>
111 <para>
112 In order to ease administration of multiple related containers, it is
113 possible to have a container configuration file cause another file to be
114 loaded. For instance, network configuration can be defined in one common
115 file which is included by multiple containers. Then, if the containers
116 are moved to another host, only one file may need to be updated.
117 </para>
118
119 <variablelist>
120 <varlistentry>
121 <term>
122 <option>lxc.include</option>
123 </term>
124 <listitem>
125 <para>
126 Specify the file to be included. The included file must be
127 in the same valid lxc configuration file format.
128 </para>
129 </listitem>
130 </varlistentry>
131 </variablelist>
132 </refsect2>
133
134 <refsect2>
135 <title>Architecture</title>
136 <para>
137 Allows one to set the architecture for the container. For example, set a
138 32bits architecture for a container running 32bits binaries on a 64bits
139 host. This fixes the container scripts which rely on the architecture to
140 do some work like downloading the packages.
141 </para>
142
143 <variablelist>
144 <varlistentry>
145 <term>
146 <option>lxc.arch</option>
147 </term>
148 <listitem>
149 <para>
150 Specify the architecture for the container.
151 </para>
152 <para>
153 Some valid options are
154 <option>x86</option>,
155 <option>i686</option>,
156 <option>x86_64</option>,
157 <option>amd64</option>
158 </para>
159 </listitem>
160 </varlistentry>
161 </variablelist>
162
163 </refsect2>
164
165 <refsect2>
166 <title>Hostname</title>
167 <para>
168 The utsname section defines the hostname to be set for the container.
169 That means the container can set its own hostname without changing the
170 one from the system. That makes the hostname private for the container.
171 </para>
172 <variablelist>
173 <varlistentry>
174 <term>
175 <option>lxc.uts.name</option>
176 </term>
177 <listitem>
178 <para>
179 specify the hostname for the container
180 </para>
181 </listitem>
182 </varlistentry>
183 </variablelist>
184 </refsect2>
185
186 <refsect2>
187 <title>Halt signal</title>
188 <para>
189 Allows one to specify signal name or number sent to the container's
190 init process to cleanly shutdown the container. Different init systems
191 could use different signals to perform clean shutdown sequence. This
192 option allows the signal to be specified in kill(1) fashion, e.g.
193 SIGPWR, SIGRTMIN+14, SIGRTMAX-10 or plain number. The default signal is
194 SIGPWR.
195 </para>
196 <variablelist>
197 <varlistentry>
198 <term>
199 <option>lxc.signal.halt</option>
200 </term>
201 <listitem>
202 <para>
203 specify the signal used to halt the container
204 </para>
205 </listitem>
206 </varlistentry>
207 </variablelist>
208 </refsect2>
209
210 <refsect2>
211 <title>Reboot signal</title>
212 <para>
213 Allows one to specify signal name or number to reboot the container.
214 This option allows signal to be specified in kill(1) fashion, e.g.
215 SIGTERM, SIGRTMIN+14, SIGRTMAX-10 or plain number. The default signal
216 is SIGINT.
217 </para>
218 <variablelist>
219 <varlistentry>
220 <term>
221 <option>lxc.signal.reboot</option>
222 </term>
223 <listitem>
224 <para>
225 specify the signal used to reboot the container
226 </para>
227 </listitem>
228 </varlistentry>
229 </variablelist>
230 </refsect2>
231
232 <refsect2>
233 <title>Stop signal</title>
234 <para>
235 Allows one to specify signal name or number to forcibly shutdown the
236 container. This option allows signal to be specified in kill(1) fashion,
237 e.g. SIGKILL, SIGRTMIN+14, SIGRTMAX-10 or plain number. The default
238 signal is SIGKILL.
239 </para>
240 <variablelist>
241 <varlistentry>
242 <term>
243 <option>lxc.signal.stop</option>
244 </term>
245 <listitem>
246 <para>
247 specify the signal used to stop the container
248 </para>
249 </listitem>
250 </varlistentry>
251 </variablelist>
252 </refsect2>
253
254 <refsect2>
255 <title>Init command</title>
256 <para>
257 Sets the command to use as the init system for the containers.
258
259 This option is ignored when using lxc-execute.
260
261 Defaults to: /sbin/init
262 </para>
263 <variablelist>
264 <varlistentry>
265 <term>
266 <option>lxc.execute.cmd</option>
267 </term>
268 <listitem>
269 <para>
270 Absolute path from container rootfs to the binary to run by default. This
271 mostly makes sense for lxc-execute.
272 </para>
273 </listitem>
274 </varlistentry>
275 </variablelist>
276 <variablelist>
277 <varlistentry>
278 <term>
279 <option>lxc.init.cmd</option>
280 </term>
281 <listitem>
282 <para>
283 Absolute path from container rootfs to the binary to use as init.
284 </para>
285 </listitem>
286 </varlistentry>
287 </variablelist>
288 </refsect2>
289
290 <refsect2>
291 <title>Init ID</title>
292 <para>
293 Sets the UID/GID to use for the init system, and subsequent commands.
294 Note that using a non-root uid when booting a system container will
295 likely not work due to missing privileges. Setting the UID/GID is mostly
296 useful when running application container.
297
298 Defaults to: UID(0), GID(0)
299 </para>
300 <variablelist>
301 <varlistentry>
302 <term>
303 <option>lxc.init.uid</option>
304 </term>
305 <listitem>
306 <para>
307 UID to use for init.
308 </para>
309 </listitem>
310 </varlistentry>
311 <varlistentry>
312 <term>
313 <option>lxc.init.gid</option>
314 </term>
315 <listitem>
316 <para>
317 GID to use for init.
318 </para>
319 </listitem>
320 </varlistentry>
321 </variablelist>
322 </refsect2>
323
324 <refsect2>
325 <title>Ephemeral</title>
326 <para>
327 Allows one to specify whether a container will be destroyed on shutdown.
328 </para>
329 <variablelist>
330 <varlistentry>
331 <term>
332 <option>lxc.ephemeral</option>
333 </term>
334 <listitem>
335 <para>
336 The only allowed values are 0 and 1. Set this to 1 to destroy a
337 container on shutdown.
338 </para>
339 </listitem>
340 </varlistentry>
341 </variablelist>
342 </refsect2>
343
344 <refsect2>
345 <title>Network</title>
346 <para>
347 The network section defines how the network is virtualized in
348 the container. The network virtualization acts at layer
349 two. In order to use the network virtualization, parameters
350 must be specified to define the network interfaces of the
351 container. Several virtual interfaces can be assigned and used
352 in a container even if the system has only one physical
353 network interface.
354 </para>
355 <variablelist>
356 <varlistentry>
357 <term>
358 <option>lxc.net</option>
359 </term>
360 <listitem>
361 <para>
362 may be used without a value to clear all previous network options.
363 </para>
364 </listitem>
365 </varlistentry>
366 <varlistentry>
367 <term>
368 <option>lxc.net.[i].type</option>
369 </term>
370 <listitem>
371 <para>
372 specify what kind of network virtualization to be used
373 for the container.
374 Multiple networks can be specified by using an additional index
375 <option>i</option>
376 after all <option>lxc.net.*</option> keys. For example,
377 <option>lxc.net.0.type = veth</option> and
378 <option>lxc.net.1.type = veth</option> specify two different
379 networks of the same type. All keys sharing the same index
380 <option>i</option> will be treated as belonging to the same
381 network. For example, <option>lxc.net.0.link = br0</option>
382 will belong to <option>lxc.net.0.type</option>.
383 Currently, the different virtualization types can be:
384 </para>
385
386 <para>
387 <option>none:</option> will cause the container to share
388 the host's network namespace. This means the host
389 network devices are usable in the container. It also
390 means that if both the container and host have upstart as
391 init, 'halt' in a container (for instance) will shut down the
392 host.
393 </para>
394
395 <para>
396 <option>empty:</option> will create only the loopback
397 interface.
398 </para>
399
400 <para>
401 <option>veth:</option> a virtual ethernet pair
402 device is created with one side assigned to the container
403 and the other side attached to a bridge specified by
404 the <option>lxc.net.[i].link</option> option.
405 If the bridge is not specified, then the veth pair device
406 will be created but not attached to any bridge.
407 Otherwise, the bridge has to be created on the system
408 before starting the container.
409 <command>lxc</command> won't handle any
410 configuration outside of the container.
411 By default, <command>lxc</command> chooses a name for the
412 network device belonging to the outside of the
413 container, but if you wish to handle
414 this name yourselves, you can tell <command>lxc</command>
415 to set a specific name with
416 the <option>lxc.net.[i].veth.pair</option> option (except for
417 unprivileged containers where this option is ignored for security
418 reasons).
419 </para>
420
421 <para>
422 <option>vlan:</option> a vlan interface is linked with
423 the interface specified by
424 the <option>lxc.net.[i].link</option> and assigned to
425 the container. The vlan identifier is specified with the
426 option <option>lxc.net.[i].vlan.id</option>.
427 </para>
428
429 <para>
430 <option>macvlan:</option> a macvlan interface is linked
431 with the interface specified by
432 the <option>lxc.net.[i].link</option> and assigned to
433 the container.
434 <option>lxc.net.[i].macvlan.mode</option> specifies the
435 mode the macvlan will use to communicate between
436 different macvlan on the same upper device. The accepted
437 modes are <option>private</option>, <option>vepa</option>,
438 <option>bridge</option> and <option>passthru</option>.
439 In <option>private</option> mode, the device never
440 communicates with any other device on the same upper_dev (default).
441 In <option>vepa</option> mode, the new Virtual Ethernet Port
442 Aggregator (VEPA) mode, it assumes that the adjacent
443 bridge returns all frames where both source and
444 destination are local to the macvlan port, i.e. the
445 bridge is set up as a reflective relay. Broadcast
446 frames coming in from the upper_dev get flooded to all
447 macvlan interfaces in VEPA mode, local frames are not
448 delivered locally. In <option>bridge</option> mode, it
449 provides the behavior of a simple bridge between
450 different macvlan interfaces on the same port. Frames
451 from one interface to another one get delivered directly
452 and are not sent out externally. Broadcast frames get
453 flooded to all other bridge ports and to the external
454 interface, but when they come back from a reflective
455 relay, we don't deliver them again. Since we know all
456 the MAC addresses, the macvlan bridge mode does not
457 require learning or STP like the bridge module does. In
458 <option>passthru</option> mode, all frames received by
459 the physical interface are forwarded to the macvlan
460 interface. Only one macvlan interface in <option>passthru</option>
461 mode is possible for one physical interface.
462 </para>
463
464 <para>
465 <option>phys:</option> an already existing interface
466 specified by the <option>lxc.net.[i].link</option> is
467 assigned to the container.
468 </para>
469 </listitem>
470 </varlistentry>
471
472 <varlistentry>
473 <term>
474 <option>lxc.net.[i].flags</option>
475 </term>
476 <listitem>
477 <para>
478 Specify an action to do for the network.
479 </para>
480
481 <para><option>up:</option> activates the interface.
482 </para>
483 </listitem>
484 </varlistentry>
485
486 <varlistentry>
487 <term>
488 <option>lxc.net.[i].link</option>
489 </term>
490 <listitem>
491 <para>
492 Specify the interface to be used for real network traffic.
493 </para>
494 </listitem>
495 </varlistentry>
496
497 <varlistentry>
498 <term>
499 <option>lxc.net.[i].mtu</option>
500 </term>
501 <listitem>
502 <para>
503 Specify the maximum transfer unit for this interface.
504 </para>
505 </listitem>
506 </varlistentry>
507
508 <varlistentry>
509 <term>
510 <option>lxc.net.[i].name</option>
511 </term>
512 <listitem>
513 <para>
514 The interface name is dynamically allocated, but if another name
515 is needed because the configuration files being used by the
516 container use a generic name, eg. eth0, this option will rename
517 the interface in the container.
518 </para>
519 </listitem>
520 </varlistentry>
521
522 <varlistentry>
523 <term>
524 <option>lxc.net.[i].hwaddr</option>
525 </term>
526 <listitem>
527 <para>
528 The interface mac address is dynamically allocated by default to
529 the virtual interface, but in some cases, this is needed to
530 resolve a mac address conflict or to always have the same
531 link-local ipv6 address. Any "x" in address will be replaced by
532 random value, this allows setting hwaddr templates.
533 </para>
534 </listitem>
535 </varlistentry>
536
537 <varlistentry>
538 <term>
539 <option>lxc.net.[i].ipv4.address</option>
540 </term>
541 <listitem>
542 <para>
543 Specify the ipv4 address to assign to the virtualized interface.
544 Several lines specify several ipv4 addresses. The address is in
545 format x.y.z.t/m, eg. 192.168.1.123/24.
546 </para>
547 </listitem>
548 </varlistentry>
549
550 <varlistentry>
551 <term>
552 <option>lxc.net.[i].ipv4.gateway</option>
553 </term>
554 <listitem>
555 <para>
556 Specify the ipv4 address to use as the gateway inside the
557 container. The address is in format x.y.z.t, eg. 192.168.1.123.
558
559 Can also have the special value <option>auto</option>,
560 which means to take the primary address from the bridge
561 interface (as specified by the
562 <option>lxc.net.[i].link</option> option) and use that as
563 the gateway. <option>auto</option> is only available when
564 using the <option>veth</option> and
565 <option>macvlan</option> network types.
566 </para>
567 </listitem>
568 </varlistentry>
569
570
571 <varlistentry>
572 <term>
573 <option>lxc.net.[i].ipv6.address</option>
574 </term>
575 <listitem>
576 <para>
577 Specify the ipv6 address to assign to the virtualized
578 interface. Several lines specify several ipv6 addresses. The
579 address is in format x::y/m, eg.
580 2003:db8:1:0:214:1234:fe0b:3596/64
581 </para>
582 </listitem>
583 </varlistentry>
584
585 <varlistentry>
586 <term>
587 <option>lxc.net.[i].ipv6.gateway</option>
588 </term>
589 <listitem>
590 <para>
591 Specify the ipv6 address to use as the gateway inside the
592 container. The address is in format x::y, eg. 2003:db8:1:0::1
593
594 Can also have the special value <option>auto</option>,
595 which means to take the primary address from the bridge
596 interface (as specified by the
597 <option>lxc.net.[i].link</option> option) and use that as
598 the gateway. <option>auto</option> is only available when
599 using the <option>veth</option> and
600 <option>macvlan</option> network types.
601 </para>
602 </listitem>
603 </varlistentry>
604
605 <varlistentry>
606 <term>
607 <option>lxc.net.[i].script.up</option>
608 </term>
609 <listitem>
610 <para>
611 Add a configuration option to specify a script to be
612 executed after creating and configuring the network used
613 from the host side. The following arguments are passed
614 to the script: container name and config section name
615 (net) Additional arguments depend on the config section
616 employing a script hook; the following are used by the
617 network system: execution context (up), network type
618 (empty/veth/macvlan/phys), Depending on the network
619 type, other arguments may be passed:
620 veth/macvlan/phys. And finally (host-sided) device name.
621 </para>
622 <para>
623 Standard output from the script is logged at debug level.
624 Standard error is not logged, but can be captured by the
625 hook redirecting its standard error to standard output.
626 </para>
627 </listitem>
628 </varlistentry>
629
630 <varlistentry>
631 <term>
632 <option>lxc.net.[i].script.down</option>
633 </term>
634 <listitem>
635 <para>
636 Add a configuration option to specify a script to be
637 executed before destroying the network used from the
638 host side. The following arguments are passed to the
639 script: container name and config section name (net)
640 Additional arguments depend on the config section
641 employing a script hook; the following are used by the
642 network system: execution context (down), network type
643 (empty/veth/macvlan/phys), Depending on the network
644 type, other arguments may be passed:
645 veth/macvlan/phys. And finally (host-sided) device name.
646 </para>
647 <para>
648 Standard output from the script is logged at debug level.
649 Standard error is not logged, but can be captured by the
650 hook redirecting its standard error to standard output.
651 </para>
652 </listitem>
653 </varlistentry>
654 </variablelist>
655 </refsect2>
656
657 <refsect2>
658 <title>New pseudo tty instance (devpts)</title>
659 <para>
660 For stricter isolation the container can have its own private
661 instance of the pseudo tty.
662 </para>
663 <variablelist>
664 <varlistentry>
665 <term>
666 <option>lxc.pty.max</option>
667 </term>
668 <listitem>
669 <para>
670 If set, the container will have a new pseudo tty
671 instance, making this private to it. The value specifies
672 the maximum number of pseudo ttys allowed for a pts
673 instance (this limitation is not implemented yet).
674 </para>
675 </listitem>
676 </varlistentry>
677 </variablelist>
678 </refsect2>
679
680 <refsect2>
681 <title>Container system console</title>
682 <para>
683 If the container is configured with a root filesystem and the
684 inittab file is setup to use the console, you may want to specify
685 where the output of this console goes.
686 </para>
687 <variablelist>
688 <varlistentry>
689 <term>
690 <option>lxc.console.logfile</option>
691 </term>
692 <listitem>
693 <para>
694 Specify a path to a file where the console output will
695 be written.
696 </para>
697 </listitem>
698 </varlistentry>
699 <varlistentry>
700 <term>
701 <option>lxc.console.path</option>
702 </term>
703 <listitem>
704 <para>
705 Specify a path to a device to which the console will be
706 attached. The keyword 'none' will simply disable the
707 console. Note, when specifying 'none' and creating a device node
708 for the console in the container at /dev/console or bind-mounting
709 the hosts's /dev/console into the container at /dev/console the
710 container will have direct access to the hosts's /dev/console.
711 This is dangerous when the container has write access to the
712 device and should thus be used with caution.
713 </para>
714 </listitem>
715 </varlistentry>
716 </variablelist>
717 </refsect2>
718
719 <refsect2>
720 <title>Console through the ttys</title>
721 <para>
722 This option is useful if the container is configured with a root
723 filesystem and the inittab file is setup to launch a getty on the
724 ttys. The option specifies the number of ttys to be available for
725 the container. The number of gettys in the inittab file of the
726 container should not be greater than the number of ttys specified
727 in this option, otherwise the excess getty sessions will die and
728 respawn indefinitely giving annoying messages on the console or in
729 <filename>/var/log/messages</filename>.
730 </para>
731 <variablelist>
732 <varlistentry>
733 <term>
734 <option>lxc.tty.max</option>
735 </term>
736 <listitem>
737 <para>
738 Specify the number of tty to make available to the
739 container.
740 </para>
741 </listitem>
742 </varlistentry>
743 </variablelist>
744 </refsect2>
745
746 <refsect2>
747 <title>Console devices location</title>
748 <para>
749 LXC consoles are provided through Unix98 PTYs created on the
750 host and bind-mounted over the expected devices in the container.
751 By default, they are bind-mounted over <filename>/dev/console</filename>
752 and <filename>/dev/ttyN</filename>. This can prevent package upgrades
753 in the guest. Therefore you can specify a directory location (under
754 <filename>/dev</filename> under which LXC will create the files and
755 bind-mount over them. These will then be symbolically linked to
756 <filename>/dev/console</filename> and <filename>/dev/ttyN</filename>.
757 A package upgrade can then succeed as it is able to remove and replace
758 the symbolic links.
759 </para>
760 <variablelist>
761 <varlistentry>
762 <term>
763 <option>lxc.tty.dir</option>
764 </term>
765 <listitem>
766 <para>
767 Specify a directory under <filename>/dev</filename>
768 under which to create the container console devices. Note that LXC
769 will move any bind-mounts or device nodes for /dev/console into
770 this directory.
771 </para>
772 </listitem>
773 </varlistentry>
774 </variablelist>
775 </refsect2>
776
777 <refsect2>
778 <title>/dev directory</title>
779 <para>
780 By default, lxc creates a few symbolic links (fd,stdin,stdout,stderr)
781 in the container's <filename>/dev</filename> directory but does not
782 automatically create device node entries. This allows the container's
783 <filename>/dev</filename> to be set up as needed in the container
784 rootfs. If lxc.autodev is set to 1, then after mounting the container's
785 rootfs LXC will mount a fresh tmpfs under <filename>/dev</filename>
786 (limited to 500k) and fill in a minimal set of initial devices.
787 This is generally required when starting a container containing
788 a "systemd" based "init" but may be optional at other times. Additional
789 devices in the containers /dev directory may be created through the
790 use of the <option>lxc.hook.autodev</option> hook.
791 </para>
792 <variablelist>
793 <varlistentry>
794 <term>
795 <option>lxc.autodev</option>
796 </term>
797 <listitem>
798 <para>
799 Set this to 0 to stop LXC from mounting and populating a minimal
800 <filename>/dev</filename> when starting the container.
801 </para>
802 </listitem>
803 </varlistentry>
804 </variablelist>
805 </refsect2>
806
807 <refsect2>
808 <title>Mount points</title>
809 <para>
810 The mount points section specifies the different places to be
811 mounted. These mount points will be private to the container
812 and won't be visible by the processes running outside of the
813 container. This is useful to mount /etc, /var or /home for
814 examples.
815 </para>
816 <para>
817 NOTE - LXC will generally ensure that mount targets and relative
818 bind-mount sources are properly confined under the container
819 root, to avoid attacks involving over-mounting host directories
820 and files. (Symbolic links in absolute mount sources are ignored)
821 However, if the container configuration first mounts a directory which
822 is under the control of the container user, such as /home/joe, into
823 the container at some <filename>path</filename>, and then mounts
824 under <filename>path</filename>, then a TOCTTOU attack would be
825 possible where the container user modifies a symbolic link under
826 his home directory at just the right time.
827 </para>
828 <variablelist>
829 <varlistentry>
830 <term>
831 <option>lxc.mount.fstab</option>
832 </term>
833 <listitem>
834 <para>
835 specify a file location in
836 the <filename>fstab</filename> format, containing the
837 mount information. The mount target location can and in
838 most cases should be a relative path, which will become
839 relative to the mounted container root. For instance,
840 </para>
841 <programlisting>
842 proc proc proc nodev,noexec,nosuid 0 0
843 </programlisting>
844 <para>
845 Will mount a proc filesystem under the container's /proc,
846 regardless of where the root filesystem comes from. This
847 is resilient to block device backed filesystems as well as
848 container cloning.
849 </para>
850 <para>
851 Note that when mounting a filesystem from an
852 image file or block device the third field (fs_vfstype)
853 cannot be auto as with
854 <citerefentry>
855 <refentrytitle>mount</refentrytitle>
856 <manvolnum>8</manvolnum>
857 </citerefentry>
858 but must be explicitly specified.
859 </para>
860 </listitem>
861 </varlistentry>
862
863 <varlistentry>
864 <term>
865 <option>lxc.mount.entry</option>
866 </term>
867 <listitem>
868 <para>
869 specify a mount point corresponding to a line in the
870 fstab format.
871
872 Moreover lxc add two options to mount.
873 <option>optional</option> don't fail if mount does not work.
874 <option>create=dir</option> or <option>create=file</option>
875 to create dir (or file) when the point will be mounted.
876 </para>
877 </listitem>
878 </varlistentry>
879
880 <varlistentry>
881 <term>
882 <option>lxc.mount.auto</option>
883 </term>
884 <listitem>
885 <para>
886 specify which standard kernel file systems should be
887 automatically mounted. This may dramatically simplify
888 the configuration. The file systems are:
889 </para>
890 <itemizedlist>
891 <listitem>
892 <para>
893 <option>proc:mixed</option> (or <option>proc</option>):
894 mount <filename>/proc</filename> as read-write, but
895 remount <filename>/proc/sys</filename> and
896 <filename>/proc/sysrq-trigger</filename> read-only
897 for security / container isolation purposes.
898 </para>
899 </listitem>
900 <listitem>
901 <para>
902 <option>proc:rw</option>: mount
903 <filename>/proc</filename> as read-write
904 </para>
905 </listitem>
906 <listitem>
907 <para>
908 <option>sys:mixed</option> (or <option>sys</option>):
909 mount <filename>/sys</filename> as read-only but with
910 /sys/devices/virtual/net writable.
911 </para>
912 </listitem>
913 <listitem>
914 <para>
915 <option>sys:ro</option>:
916 mount <filename>/sys</filename> as read-only
917 for security / container isolation purposes.
918 </para>
919 </listitem>
920 <listitem>
921 <para>
922 <option>sys:rw</option>: mount
923 <filename>/sys</filename> as read-write
924 </para>
925 </listitem>
926 <listitem>
927 <para>
928 <option>cgroup:mixed</option>:
929 mount a tmpfs to <filename>/sys/fs/cgroup</filename>,
930 create directories for all hierarchies to which
931 the container is added, create subdirectories
932 there with the name of the cgroup, and bind-mount
933 the container's own cgroup into that directory.
934 The container will be able to write to its own
935 cgroup directory, but not the parents, since they
936 will be remounted read-only.
937 </para>
938 </listitem>
939 <listitem>
940 <para>
941 <option>cgroup:ro</option>: similar to
942 <option>cgroup:mixed</option>, but everything will
943 be mounted read-only.
944 </para>
945 </listitem>
946 <listitem>
947 <para>
948 <option>cgroup:rw</option>: similar to
949 <option>cgroup:mixed</option>, but everything will
950 be mounted read-write. Note that the paths leading
951 up to the container's own cgroup will be writable,
952 but will not be a cgroup filesystem but just part
953 of the tmpfs of <filename>/sys/fs/cgroup</filename>
954 </para>
955 </listitem>
956 <listitem>
957 <para>
958 <option>cgroup</option> (without specifier):
959 defaults to <option>cgroup:rw</option> if the
960 container retains the CAP_SYS_ADMIN capability,
961 <option>cgroup:mixed</option> otherwise.
962 </para>
963 </listitem>
964 <listitem>
965 <para>
966 <option>cgroup-full:mixed</option>:
967 mount a tmpfs to <filename>/sys/fs/cgroup</filename>,
968 create directories for all hierarchies to which
969 the container is added, bind-mount the hierarchies
970 from the host to the container and make everything
971 read-only except the container's own cgroup. Note
972 that compared to <option>cgroup</option>, where
973 all paths leading up to the container's own cgroup
974 are just simple directories in the underlying
975 tmpfs, here
976 <filename>/sys/fs/cgroup/$hierarchy</filename>
977 will contain the host's full cgroup hierarchy,
978 albeit read-only outside the container's own cgroup.
979 This may leak quite a bit of information into the
980 container.
981 </para>
982 </listitem>
983 <listitem>
984 <para>
985 <option>cgroup-full:ro</option>: similar to
986 <option>cgroup-full:mixed</option>, but everything
987 will be mounted read-only.
988 </para>
989 </listitem>
990 <listitem>
991 <para>
992 <option>cgroup-full:rw</option>: similar to
993 <option>cgroup-full:mixed</option>, but everything
994 will be mounted read-write. Note that in this case,
995 the container may escape its own cgroup. (Note also
996 that if the container has CAP_SYS_ADMIN support
997 and can mount the cgroup filesystem itself, it may
998 do so anyway.)
999 </para>
1000 </listitem>
1001 <listitem>
1002 <para>
1003 <option>cgroup-full</option> (without specifier):
1004 defaults to <option>cgroup-full:rw</option> if the
1005 container retains the CAP_SYS_ADMIN capability,
1006 <option>cgroup-full:mixed</option> otherwise.
1007 </para>
1008 </listitem>
1009 </itemizedlist>
1010 <para>
1011 If cgroup namespaces are enabled, then any <option>cgroup</option>
1012 auto-mounting request will be ignored, since the container can
1013 mount the filesystems itself, and automounting can confuse the
1014 container init.
1015 </para>
1016 <para>
1017 Note that if automatic mounting of the cgroup filesystem
1018 is enabled, the tmpfs under
1019 <filename>/sys/fs/cgroup</filename> will always be
1020 mounted read-write (but for the <option>:mixed</option>
1021 and <option>:ro</option> cases, the individual
1022 hierarchies,
1023 <filename>/sys/fs/cgroup/$hierarchy</filename>, will be
1024 read-only). This is in order to work around a quirk in
1025 Ubuntu's
1026 <citerefentry>
1027 <refentrytitle>mountall</refentrytitle>
1028 <manvolnum>8</manvolnum>
1029 </citerefentry>
1030 command that will cause containers to wait for user
1031 input at boot if
1032 <filename>/sys/fs/cgroup</filename> is mounted read-only
1033 and the container can't remount it read-write due to a
1034 lack of CAP_SYS_ADMIN.
1035 </para>
1036 <para>
1037 Examples:
1038 </para>
1039 <programlisting>
1040 lxc.mount.auto = proc sys cgroup
1041 lxc.mount.auto = proc:rw sys:rw cgroup-full:rw
1042 </programlisting>
1043 </listitem>
1044 </varlistentry>
1045
1046 </variablelist>
1047 </refsect2>
1048
1049 <refsect2>
1050 <title>Root file system</title>
1051 <para>
1052 The root file system of the container can be different than that
1053 of the host system.
1054 </para>
1055 <variablelist>
1056 <varlistentry>
1057 <term>
1058 <option>lxc.rootfs.path</option>
1059 </term>
1060 <listitem>
1061 <para>
1062 specify the root file system for the container. It can
1063 be an image file, a directory or a block device. If not
1064 specified, the container shares its root file system
1065 with the host.
1066 </para>
1067 <para>
1068 For directory or simple block-device backed containers,
1069 a pathname can be used. If the rootfs is backed by a nbd
1070 device, then <filename>nbd:file:1</filename> specifies that
1071 <filename>file</filename> should be attached to a nbd device,
1072 and partition 1 should be mounted as the rootfs.
1073 <filename>nbd:file</filename> specifies that the nbd device
1074 itself should be mounted. <filename>overlayfs:/lower:/upper</filename>
1075 specifies that the rootfs should be an overlay with <filename>/upper</filename>
1076 being mounted read-write over a read-only mount of <filename>/lower</filename>.
1077 <filename>aufs:/lower:/upper</filename> does the same using aufs in place
1078 of overlayfs. For both <filename>overlayfs</filename> and
1079 <filename>aufs</filename> multiple <filename>/lower</filename>
1080 directories can be specified. <filename>loop:/file</filename> tells lxc to attach
1081 <filename>/file</filename> to a loop device and mount the loop device.
1082 </para>
1083 </listitem>
1084 </varlistentry>
1085
1086 <varlistentry>
1087 <term>
1088 <option>lxc.rootfs.mount</option>
1089 </term>
1090 <listitem>
1091 <para>
1092 where to recursively bind <option>lxc.rootfs.path</option>
1093 before pivoting. This is to ensure success of the
1094 <citerefentry>
1095 <refentrytitle><command>pivot_root</command></refentrytitle>
1096 <manvolnum>8</manvolnum>
1097 </citerefentry>
1098 syscall. Any directory suffices, the default should
1099 generally work.
1100 </para>
1101 </listitem>
1102 </varlistentry>
1103
1104 <varlistentry>
1105 <term>
1106 <option>lxc.rootfs.options</option>
1107 </term>
1108 <listitem>
1109 <para>
1110 extra mount options to use when mounting the rootfs.
1111 </para>
1112 </listitem>
1113 </varlistentry>
1114
1115 </variablelist>
1116 </refsect2>
1117
1118 <refsect2>
1119 <title>Control group</title>
1120 <para>
1121 The control group section contains the configuration for the
1122 different subsystem. <command>lxc</command> does not check the
1123 correctness of the subsystem name. This has the disadvantage
1124 of not detecting configuration errors until the container is
1125 started, but has the advantage of permitting any future
1126 subsystem.
1127 </para>
1128 <variablelist>
1129 <varlistentry>
1130 <term>
1131 <option>lxc.cgroup.[subsystem name]</option>
1132 </term>
1133 <listitem>
1134 <para>
1135 specify the control group value to be set. The
1136 subsystem name is the literal name of the control group
1137 subsystem. The permitted names and the syntax of their
1138 values is not dictated by LXC, instead it depends on the
1139 features of the Linux kernel running at the time the
1140 container is started,
1141 eg. <option>lxc.cgroup.cpuset.cpus</option>
1142 </para>
1143 </listitem>
1144 </varlistentry>
1145 <varlistentry>
1146 <term>
1147 <option>lxc.cgroup.dir</option>
1148 </term>
1149 <listitem>
1150 <para>
1151 specify a directory or path in which the container's cgroup will
1152 be created. For example, setting
1153 <option>lxc.cgroup.dir = my-cgroup/first</option> for a container
1154 named "c1" will create the container's cgroup as a sub-cgroup of
1155 "my-cgroup". For example, if the user's current cgroup "my-user"
1156 is located in the root cgroup of the cpuset controller in a
1157 cgroup v1 hierarchy this would create the cgroup
1158 "/sys/fs/cgroup/cpuset/my-user/my-cgroup/first/c1" for the
1159 container. Any missing cgroups will be created by LXC. This
1160 presupposes that the user has write access to its current cgroup.
1161 </para>
1162 </listitem>
1163 </varlistentry>
1164 </variablelist>
1165 </refsect2>
1166
1167 <refsect2>
1168 <title>Capabilities</title>
1169 <para>
1170 The capabilities can be dropped in the container if this one
1171 is run as root.
1172 </para>
1173 <variablelist>
1174 <varlistentry>
1175 <term>
1176 <option>lxc.cap.drop</option>
1177 </term>
1178 <listitem>
1179 <para>
1180 Specify the capability to be dropped in the container. A
1181 single line defining several capabilities with a space
1182 separation is allowed. The format is the lower case of
1183 the capability definition without the "CAP_" prefix,
1184 eg. CAP_SYS_MODULE should be specified as
1185 sys_module. See
1186 <citerefentry>
1187 <refentrytitle><command>capabilities</command></refentrytitle>
1188 <manvolnum>7</manvolnum>
1189 </citerefentry>.
1190 If used with no value, lxc will clear any drop capabilities
1191 specified up to this point.
1192 </para>
1193 </listitem>
1194 </varlistentry>
1195 <varlistentry>
1196 <term>
1197 <option>lxc.cap.keep</option>
1198 </term>
1199 <listitem>
1200 <para>
1201 Specify the capability to be kept in the container. All other
1202 capabilities will be dropped. When a special value of "none" is
1203 encountered, lxc will clear any keep capabilities specified up
1204 to this point. A value of "none" alone can be used to drop all
1205 capabilities.
1206 </para>
1207 </listitem>
1208 </varlistentry>
1209 </variablelist>
1210 </refsect2>
1211
1212 <refsect2>
1213 <title>Resource limits</title>
1214 <para>
1215 The soft and hard resource limits for the container can be changed.
1216 Unprivileged containers can only lower them. Resources which are not
1217 explicitly specified will be inherited.
1218 </para>
1219 <variablelist>
1220 <varlistentry>
1221 <term>
1222 <option>lxc.prlimit.[limit name]</option>
1223 </term>
1224 <listitem>
1225 <para>
1226 Specify the resource limit to be set. A limit is specified as two
1227 colon separated values which are either numeric or the word
1228 'unlimited'. A single value can be used as a shortcut to set both
1229 soft and hard limit to the same value. The permitted names the
1230 "RLIMIT_" resource names in lowercase without the "RLIMIT_"
1231 prefix, eg. RLIMIT_NOFILE should be specified as "nofile". See
1232 <citerefentry>
1233 <refentrytitle><command>setrlimit</command></refentrytitle>
1234 <manvolnum>2</manvolnum>
1235 </citerefentry>.
1236 If used with no value, lxc will clear the resource limit
1237 specified up to this point. A resource with no explicitly
1238 configured limitation will be inherited from the process starting
1239 up the container.
1240 </para>
1241 </listitem>
1242 </varlistentry>
1243 </variablelist>
1244 </refsect2>
1245
1246 <refsect2>
1247 <title>Apparmor profile</title>
1248 <para>
1249 If lxc was compiled and installed with apparmor support, and the host
1250 system has apparmor enabled, then the apparmor profile under which the
1251 container should be run can be specified in the container
1252 configuration. The default is <command>lxc-container-default-cgns</command>
1253 if the host kernel is cgroup namespace aware, or
1254 <command>lxc-container-default</command> othewise.
1255 </para>
1256 <variablelist>
1257 <varlistentry>
1258 <term>
1259 <option>lxc.apparmor.profile</option>
1260 </term>
1261 <listitem>
1262 <para>
1263 Specify the apparmor profile under which the container should
1264 be run. To specify that the container should be unconfined,
1265 use
1266 </para>
1267 <programlisting>lxc.apparmor.profile = unconfined</programlisting>
1268 <para>
1269 If the apparmor profile should remain unchanged (i.e. if you
1270 are nesting containers and are already confined), then use
1271 </para>
1272 <programlisting>lxc.apparmor.profile = unchanged</programlisting>
1273 </listitem>
1274 </varlistentry>
1275 <varlistentry>
1276 <term>
1277 <option>lxc.apparmor.allow_incomplete</option>
1278 </term>
1279 <listitem>
1280 <para>
1281 Apparmor profiles are pathname based. Therefore many file
1282 restrictions require mount restrictions to be effective against
1283 a determined attacker. However, these mount restrictions are not
1284 yet implemented in the upstream kernel. Without the mount
1285 restrictions, the apparmor profiles still protect against accidental
1286 damager.
1287 </para>
1288 <para>
1289 If this flag is 0 (default), then the container will not be
1290 started if the kernel lacks the apparmor mount features, so that a
1291 regression after a kernel upgrade will be detected. To start the
1292 container under partial apparmor protection, set this flag to 1.
1293 </para>
1294 </listitem>
1295 </varlistentry>
1296 </variablelist>
1297 </refsect2>
1298
1299 <refsect2>
1300 <title>SELinux context</title>
1301 <para>
1302 If lxc was compiled and installed with SELinux support, and the host
1303 system has SELinux enabled, then the SELinux context under which the
1304 container should be run can be specified in the container
1305 configuration. The default is <command>unconfined_t</command>,
1306 which means that lxc will not attempt to change contexts.
1307 See @DATADIR@/lxc/selinux/lxc.te for an example policy and more
1308 information.
1309 </para>
1310 <variablelist>
1311 <varlistentry>
1312 <term>
1313 <option>lxc.selinux.context</option>
1314 </term>
1315 <listitem>
1316 <para>
1317 Specify the SELinux context under which the container should
1318 be run or <command>unconfined_t</command>. For example
1319 </para>
1320 <programlisting>lxc.selinux.context = system_u:system_r:lxc_t:s0:c22</programlisting>
1321 </listitem>
1322 </varlistentry>
1323 </variablelist>
1324 </refsect2>
1325
1326 <refsect2>
1327 <title>Seccomp configuration</title>
1328 <para>
1329 A container can be started with a reduced set of available
1330 system calls by loading a seccomp profile at startup. The
1331 seccomp configuration file must begin with a version number
1332 on the first line, a policy type on the second line, followed
1333 by the configuration.
1334 </para>
1335 <para>
1336 Versions 1 and 2 are currently supported. In version 1, the
1337 policy is a simple whitelist. The second line therefore must
1338 read "whitelist", with the rest of the file containing one (numeric)
1339 sycall number per line. Each syscall number is whitelisted,
1340 while every unlisted number is blacklisted for use in the container
1341 </para>
1342
1343 <para>
1344 In version 2, the policy may be blacklist or whitelist,
1345 supports per-rule and per-policy default actions, and supports
1346 per-architecture system call resolution from textual names.
1347 </para>
1348 <para>
1349 An example blacklist policy, in which all system calls are
1350 allowed except for mknod, which will simply do nothing and
1351 return 0 (success), looks like:
1352 </para>
1353
1354 <programlisting>
1355 2
1356 blacklist
1357 mknod errno 0
1358 </programlisting>
1359
1360 <variablelist>
1361 <varlistentry>
1362 <term>
1363 <option>lxc.seccomp.profile</option>
1364 </term>
1365 <listitem>
1366 <para>
1367 Specify a file containing the seccomp configuration to
1368 load before the container starts.
1369 </para>
1370 </listitem>
1371 </varlistentry>
1372 </variablelist>
1373 </refsect2>
1374
1375 <refsect2>
1376 <title>PR_SET_NO_NEW_PRIVS</title>
1377 <para>
1378 With PR_SET_NO_NEW_PRIVS active execve() promises not to grant
1379 privileges to do anything that could not have been done without
1380 the execve() call (for example, rendering the set-user-ID and
1381 set-group-ID mode bits, and file capabilities non-functional).
1382 Once set, this bit cannot be unset. The setting of this bit is
1383 inherited by children created by fork() and clone(), and preserved
1384 across execve().
1385 Note that PR_SET_NO_NEW_PRIVS is applied after the container has
1386 changed into its intended AppArmor profile or SElinux context.
1387 </para>
1388 <variablelist>
1389 <varlistentry>
1390 <term>
1391 <option>lxc.no_new_privs</option>
1392 </term>
1393 <listitem>
1394 <para>
1395 Specify whether the PR_SET_NO_NEW_PRIVS flag should be set for the
1396 container. Set to 1 to activate.
1397 </para>
1398 </listitem>
1399 </varlistentry>
1400 </variablelist>
1401 </refsect2>
1402
1403 <refsect2>
1404 <title>UID mappings</title>
1405 <para>
1406 A container can be started in a private user namespace with
1407 user and group id mappings. For instance, you can map userid
1408 0 in the container to userid 200000 on the host. The root
1409 user in the container will be privileged in the container,
1410 but unprivileged on the host. Normally a system container
1411 will want a range of ids, so you would map, for instance,
1412 user and group ids 0 through 20,000 in the container to the
1413 ids 200,000 through 220,000.
1414 </para>
1415 <variablelist>
1416 <varlistentry>
1417 <term>
1418 <option>lxc.idmap</option>
1419 </term>
1420 <listitem>
1421 <para>
1422 Four values must be provided. First a character, either
1423 'u', or 'g', to specify whether user or group ids are
1424 being mapped. Next is the first userid as seen in the
1425 user namespace of the container. Next is the userid as
1426 seen on the host. Finally, a range indicating the number
1427 of consecutive ids to map.
1428 </para>
1429 </listitem>
1430 </varlistentry>
1431 </variablelist>
1432 </refsect2>
1433
1434 <refsect2>
1435 <title>Container hooks</title>
1436 <para>
1437 Container hooks are programs or scripts which can be executed
1438 at various times in a container's lifetime.
1439 </para>
1440 <para>
1441 When a container hook is executed, information is passed both
1442 as command line arguments and through environment variables.
1443 The arguments are:
1444 <itemizedlist>
1445 <listitem><para> Container name. </para></listitem>
1446 <listitem><para> Section (always 'lxc'). </para></listitem>
1447 <listitem><para> The hook type (i.e. 'clone' or 'pre-mount'). </para></listitem>
1448 <listitem><para> Additional arguments. In the
1449 case of the clone hook, any extra arguments passed to
1450 lxc-clone will appear as further arguments to the hook.
1451 In the case of the stop hook, paths to filedescriptors
1452 for each of the container's namespaces along with their types
1453 are passed. </para></listitem>
1454 </itemizedlist>
1455 The following environment variables are set:
1456 <itemizedlist>
1457 <listitem><para> LXC_NAME: is the container's name. </para></listitem>
1458 <listitem><para> LXC_ROOTFS_MOUNT: the path to the mounted root filesystem. </para></listitem>
1459 <listitem><para> LXC_CONFIG_FILE: the path to the container configuration file. </para></listitem>
1460 <listitem><para> LXC_SRC_NAME: in the case of the clone hook, this is the original container's name. </para></listitem>
1461 <listitem><para> LXC_ROOTFS_PATH: this is the lxc.rootfs.path entry for the container. Note this is likely not where the mounted rootfs is to be found, use LXC_ROOTFS_MOUNT for that. </para></listitem>
1462 <listitem><para> LXC_CGNS_AWARE: indicated whether the container is cgroup namespace aware. </para></listitem>
1463 <listitem><para> LXC_LOG_LEVEL: the container's log level. </para></listitem>
1464 </itemizedlist>
1465 </para>
1466 <para>
1467 Standard output from the hooks is logged at debug level.
1468 Standard error is not logged, but can be captured by the
1469 hook redirecting its standard error to standard output.
1470 </para>
1471 <variablelist>
1472 <varlistentry>
1473 <term>
1474 <option>lxc.hook.pre-start</option>
1475 </term>
1476 <listitem>
1477 <para>
1478 A hook to be run in the host's namespace before the
1479 container ttys, consoles, or mounts are up.
1480 </para>
1481 </listitem>
1482 </varlistentry>
1483 </variablelist>
1484 <variablelist>
1485 <varlistentry>
1486 <term>
1487 <option>lxc.hook.pre-mount</option>
1488 </term>
1489 <listitem>
1490 <para>
1491 A hook to be run in the container's fs namespace but before
1492 the rootfs has been set up. This allows for manipulation
1493 of the rootfs, i.e. to mount an encrypted filesystem. Mounts
1494 done in this hook will not be reflected on the host (apart from
1495 mounts propagation), so they will be automatically cleaned up
1496 when the container shuts down.
1497 </para>
1498 </listitem>
1499 </varlistentry>
1500 </variablelist>
1501 <variablelist>
1502 <varlistentry>
1503 <term>
1504 <option>lxc.hook.mount</option>
1505 </term>
1506 <listitem>
1507 <para>
1508 A hook to be run in the container's namespace after
1509 mounting has been done, but before the pivot_root.
1510 </para>
1511 </listitem>
1512 </varlistentry>
1513 </variablelist>
1514 <variablelist>
1515 <varlistentry>
1516 <term>
1517 <option>lxc.hook.autodev</option>
1518 </term>
1519 <listitem>
1520 <para>
1521 A hook to be run in the container's namespace after
1522 mounting has been done and after any mount hooks have
1523 run, but before the pivot_root, if
1524 <option>lxc.autodev</option> == 1.
1525 The purpose of this hook is to assist in populating the
1526 /dev directory of the container when using the autodev
1527 option for systemd based containers. The container's /dev
1528 directory is relative to the
1529 ${<option>LXC_ROOTFS_MOUNT</option>} environment
1530 variable available when the hook is run.
1531 </para>
1532 </listitem>
1533 </varlistentry>
1534 </variablelist>
1535 <variablelist>
1536 <varlistentry>
1537 <term>
1538 <option>lxc.hook.start-host</option>
1539 </term>
1540 <listitem>
1541 <para>
1542 A hook to be run in the host's namespace after the
1543 container has been setup, and immediately before starting
1544 the container init.
1545 </para>
1546 </listitem>
1547 </varlistentry>
1548 </variablelist>
1549 <variablelist>
1550 <varlistentry>
1551 <term>
1552 <option>lxc.hook.start</option>
1553 </term>
1554 <listitem>
1555 <para>
1556 A hook to be run in the container's namespace immediately
1557 before executing the container's init. This requires the
1558 program to be available in the container.
1559 </para>
1560 </listitem>
1561 </varlistentry>
1562 </variablelist>
1563 <variablelist>
1564 <varlistentry>
1565 <term>
1566 <option>lxc.hook.stop</option>
1567 </term>
1568 <listitem>
1569 <para>
1570 A hook to be run in the host's namespace with references
1571 to the container's namespaces after the container has been shut
1572 down. For each namespace an extra argument is passed to the hook
1573 containing the namespace's type and a filename that can be used to
1574 obtain a file descriptor to the corresponding namespace, separated
1575 by a colon. The type is the name as it would appear in the
1576 <filename>/proc/PID/ns</filename> directory.
1577 For instance for the mount namespace the argument usually looks
1578 like <filename>mnt:/proc/PID/fd/12</filename>.
1579 </para>
1580 </listitem>
1581 </varlistentry>
1582 </variablelist>
1583 <variablelist>
1584 <varlistentry>
1585 <term>
1586 <option>lxc.hook.post-stop</option>
1587 </term>
1588 <listitem>
1589 <para>
1590 A hook to be run in the host's namespace after the
1591 container has been shut down.
1592 </para>
1593 </listitem>
1594 </varlistentry>
1595 </variablelist>
1596 <variablelist>
1597 <varlistentry>
1598 <term>
1599 <option>lxc.hook.clone</option>
1600 </term>
1601 <listitem>
1602 <para>
1603 A hook to be run when the container is cloned to a new one.
1604 See <citerefentry><refentrytitle><command>lxc-clone</command></refentrytitle>
1605 <manvolnum>1</manvolnum></citerefentry> for more information.
1606 </para>
1607 </listitem>
1608 </varlistentry>
1609 </variablelist>
1610 <variablelist>
1611 <varlistentry>
1612 <term>
1613 <option>lxc.hook.destroy</option>
1614 </term>
1615 <listitem>
1616 <para>
1617 A hook to be run when the container is destroyed.
1618 </para>
1619 </listitem>
1620 </varlistentry>
1621 </variablelist>
1622 </refsect2>
1623
1624 <refsect2>
1625 <title>Container hooks Environment Variables</title>
1626 <para>
1627 A number of environment variables are made available to the startup
1628 hooks to provide configuration information and assist in the
1629 functioning of the hooks. Not all variables are valid in all
1630 contexts. In particular, all paths are relative to the host system
1631 and, as such, not valid during the <option>lxc.hook.start</option> hook.
1632 </para>
1633 <variablelist>
1634 <varlistentry>
1635 <term>
1636 <option>LXC_NAME</option>
1637 </term>
1638 <listitem>
1639 <para>
1640 The LXC name of the container. Useful for logging messages
1641 in common log environments. [<option>-n</option>]
1642 </para>
1643 </listitem>
1644 </varlistentry>
1645 </variablelist>
1646 <variablelist>
1647 <varlistentry>
1648 <term>
1649 <option>LXC_CONFIG_FILE</option>
1650 </term>
1651 <listitem>
1652 <para>
1653 Host relative path to the container configuration file. This
1654 gives the container to reference the original, top level,
1655 configuration file for the container in order to locate any
1656 additional configuration information not otherwise made
1657 available. [<option>-f</option>]
1658 </para>
1659 </listitem>
1660 </varlistentry>
1661 </variablelist>
1662 <variablelist>
1663 <varlistentry>
1664 <term>
1665 <option>LXC_CONSOLE</option>
1666 </term>
1667 <listitem>
1668 <para>
1669 The path to the console output of the container if not NULL.
1670 [<option>-c</option>] [<option>lxc.console.path</option>]
1671 </para>
1672 </listitem>
1673 </varlistentry>
1674 </variablelist>
1675 <variablelist>
1676 <varlistentry>
1677 <term>
1678 <option>LXC_CONSOLE_LOGPATH</option>
1679 </term>
1680 <listitem>
1681 <para>
1682 The path to the console log output of the container if not NULL.
1683 [<option>-L</option>]
1684 </para>
1685 </listitem>
1686 </varlistentry>
1687 </variablelist>
1688 <variablelist>
1689 <varlistentry>
1690 <term>
1691 <option>LXC_ROOTFS_MOUNT</option>
1692 </term>
1693 <listitem>
1694 <para>
1695 The mount location to which the container is initially bound.
1696 This will be the host relative path to the container rootfs
1697 for the container instance being started and is where changes
1698 should be made for that instance.
1699 [<option>lxc.rootfs.mount</option>]
1700 </para>
1701 </listitem>
1702 </varlistentry>
1703 </variablelist>
1704 <variablelist>
1705 <varlistentry>
1706 <term>
1707 <option>LXC_ROOTFS_PATH</option>
1708 </term>
1709 <listitem>
1710 <para>
1711 The host relative path to the container root which has been
1712 mounted to the rootfs.mount location.
1713 [<option>lxc.rootfs.path</option>]
1714 </para>
1715 </listitem>
1716 </varlistentry>
1717 </variablelist>
1718 <variablelist>
1719 <varlistentry>
1720 <term>
1721 <option>LXC_SRC_NAME</option>
1722 </term>
1723 <listitem>
1724 <para>
1725 Only for the clone hook. Is set to the original container name.
1726 </para>
1727 </listitem>
1728 </varlistentry>
1729 </variablelist>
1730 <variablelist>
1731 <varlistentry>
1732 <term>
1733 <option>LXC_TARGET</option>
1734 </term>
1735 <listitem>
1736 <para>
1737 Only for the stop hook. Is set to "stop" for a container
1738 shutdown or "reboot" for a container reboot.
1739 </para>
1740 </listitem>
1741 </varlistentry>
1742 </variablelist>
1743 <variablelist>
1744 <varlistentry>
1745 <term>
1746 <option>LXC_CGNS_AWARE</option>
1747 </term>
1748 <listitem>
1749 <para>
1750 If unset, then this version of lxc is not aware of cgroup
1751 namespaces. If set, it will be set to 1, and lxc is aware
1752 of cgroup namespaces. Note this does not guarantee that
1753 cgroup namespaces are enabled in the kernel. This is used
1754 by the lxcfs mount hook.
1755 </para>
1756 </listitem>
1757 </varlistentry>
1758 </variablelist>
1759 </refsect2>
1760 <refsect2>
1761 <title>Logging</title>
1762 <para>
1763 Logging can be configured on a per-container basis. By default,
1764 depending upon how the lxc package was compiled, container startup
1765 is logged only at the ERROR level, and logged to a file named after
1766 the container (with '.log' appended) either under the container path,
1767 or under @LOGPATH@.
1768 </para>
1769 <para>
1770 Both the default log level and the log file can be specified in the
1771 container configuration file, overriding the default behavior. Note
1772 that the configuration file entries can in turn be overridden by the
1773 command line options to <command>lxc-start</command>.
1774 </para>
1775 <variablelist>
1776 <varlistentry>
1777 <term>
1778 <option>lxc.log.level</option>
1779 </term>
1780 <listitem>
1781 <para>
1782 The level at which to log. The log level is an integer in
1783 the range of 0..8 inclusive, where a lower number means more
1784 verbose debugging. In particular 0 = trace, 1 = debug, 2 =
1785 info, 3 = notice, 4 = warn, 5 = error, 6 = critical, 7 =
1786 alert, and 8 = fatal. If unspecified, the level defaults
1787 to 5 (error), so that only errors and above are logged.
1788 </para>
1789 <para>
1790 Note that when a script (such as either a hook script or a
1791 network interface up or down script) is called, the script's
1792 standard output is logged at level 1, debug.
1793 </para>
1794 </listitem>
1795 </varlistentry>
1796 <varlistentry>
1797 <term>
1798 <option>lxc.log</option>
1799 </term>
1800 <listitem>
1801 <para>
1802 The file to which logging info should be written.
1803 </para>
1804 </listitem>
1805 </varlistentry>
1806 <varlistentry>
1807 <term>
1808 <option>lxc.log.syslog</option>
1809 </term>
1810 <listitem>
1811 <para>
1812 Send logging info to syslog. It respects the log level defined in
1813 <command>lxc.log.level</command>. The argument should be the syslog
1814 facility to use, valid ones are: daemon, local0, local1, local2,
1815 local3, local4, local5, local5, local6, local7.
1816 </para>
1817 </listitem>
1818 </varlistentry>
1819 </variablelist>
1820 </refsect2>
1821
1822 <refsect2>
1823 <title>Autostart</title>
1824 <para>
1825 The autostart options support marking which containers should be
1826 auto-started and in what order. These options may be used by LXC tools
1827 directly or by external tooling provided by the distributions.
1828 </para>
1829
1830 <variablelist>
1831 <varlistentry>
1832 <term>
1833 <option>lxc.start.auto</option>
1834 </term>
1835 <listitem>
1836 <para>
1837 Whether the container should be auto-started.
1838 Valid values are 0 (off) and 1 (on).
1839 </para>
1840 </listitem>
1841 </varlistentry>
1842 <varlistentry>
1843 <term>
1844 <option>lxc.start.delay</option>
1845 </term>
1846 <listitem>
1847 <para>
1848 How long to wait (in seconds) after the container is
1849 started before starting the next one.
1850 </para>
1851 </listitem>
1852 </varlistentry>
1853 <varlistentry>
1854 <term>
1855 <option>lxc.start.order</option>
1856 </term>
1857 <listitem>
1858 <para>
1859 An integer used to sort the containers when auto-starting
1860 a series of containers at once.
1861 </para>
1862 </listitem>
1863 </varlistentry>
1864 <varlistentry>
1865 <term>
1866 <option>lxc.monitor.unshare</option>
1867 </term>
1868 <listitem>
1869 <para>
1870 If not zero the mount namespace will be unshared from the host
1871 before initializing the container (before running any pre-start
1872 hooks). This requires the CAP_SYS_ADMIN capability at startup.
1873 Default is 0.
1874 </para>
1875 </listitem>
1876 </varlistentry>
1877 <varlistentry>
1878 <term>
1879 <option>lxc.group</option>
1880 </term>
1881 <listitem>
1882 <para>
1883 A multi-value key (can be used multiple times) to put the
1884 container in a container group. Those groups can then be
1885 used (amongst other things) to start a series of related
1886 containers.
1887 </para>
1888 </listitem>
1889 </varlistentry>
1890 </variablelist>
1891 </refsect2>
1892
1893 <refsect2>
1894 <title>Autostart and System Boot</title>
1895 <para>
1896 Each container can be part of any number of groups or no group at all.
1897 Two groups are special. One is the NULL group, i.e. the container does
1898 not belong to any group. The other group is the "onboot" group.
1899 </para>
1900
1901 <para>
1902 When the system boots with the LXC service enabled, it will first
1903 attempt to boot any containers with lxc.start.auto == 1 that is a member
1904 of the "onboot" group. The startup will be in order of lxc.start.order.
1905 If an lxc.start.delay has been specified, that delay will be honored
1906 before attempting to start the next container to give the current
1907 container time to begin initialization and reduce overloading the host
1908 system. After starting the members of the "onboot" group, the LXC system
1909 will proceed to boot containers with lxc.start.auto == 1 which are not
1910 members of any group (the NULL group) and proceed as with the onboot
1911 group.
1912 </para>
1913
1914 </refsect2>
1915
1916 <refsect2>
1917 <title>Container Environment</title>
1918 <para>
1919 If you want to pass environment variables into the container (that
1920 is, environment variables which will be available to init and all of
1921 its descendents), you can use <command>lxc.environment</command>
1922 parameters to do so. Be careful that you do not pass in anything
1923 sensitive; any process in the container which doesn't have its
1924 environment scrubbed will have these variables available to it, and
1925 environment variables are always available via
1926 <command>/proc/PID/environ</command>.
1927 </para>
1928
1929 <para>
1930 This configuration parameter can be specified multiple times; once
1931 for each environment variable you wish to configure.
1932 </para>
1933
1934 <variablelist>
1935 <varlistentry>
1936 <term>
1937 <option>lxc.environment</option>
1938 </term>
1939 <listitem>
1940 <para>
1941 Specify an environment variable to pass into the container.
1942 Example:
1943 </para>
1944 <programlisting>
1945 lxc.environment = APP_ENV=production
1946 lxc.environment = SYSLOG_SERVER=192.0.2.42
1947 </programlisting>
1948 </listitem>
1949 </varlistentry>
1950 </variablelist>
1951 </refsect2>
1952
1953 </refsect1>
1954
1955 <refsect1>
1956 <title>Examples</title>
1957 <para>
1958 In addition to the few examples given below, you will find
1959 some other examples of configuration file in @DOCDIR@/examples
1960 </para>
1961 <refsect2>
1962 <title>Network</title>
1963 <para>This configuration sets up a container to use a veth pair
1964 device with one side plugged to a bridge br0 (which has been
1965 configured before on the system by the administrator). The
1966 virtual network device visible in the container is renamed to
1967 eth0.</para>
1968 <programlisting>
1969 lxc.uts.name = myhostname
1970 lxc.net.0.type = veth
1971 lxc.net.0.flags = up
1972 lxc.net.0.link = br0
1973 lxc.net.0.name = eth0
1974 lxc.net.0.hwaddr = 4a:49:43:49:79:bf
1975 lxc.net.0.ipv4.address = 10.2.3.5/24 10.2.3.255
1976 lxc.net.0.ipv6.address = 2003:db8:1:0:214:1234:fe0b:3597
1977 </programlisting>
1978 </refsect2>
1979
1980 <refsect2>
1981 <title>UID/GID mapping</title>
1982 <para>This configuration will map both user and group ids in the
1983 range 0-9999 in the container to the ids 100000-109999 on the host.
1984 </para>
1985 <programlisting>
1986 lxc.idmap = u 0 100000 10000
1987 lxc.idmap = g 0 100000 10000
1988 </programlisting>
1989 </refsect2>
1990
1991 <refsect2>
1992 <title>Control group</title>
1993 <para>This configuration will setup several control groups for
1994 the application, cpuset.cpus restricts usage of the defined cpu,
1995 cpus.share prioritize the control group, devices.allow makes
1996 usable the specified devices.</para>
1997 <programlisting>
1998 lxc.cgroup.cpuset.cpus = 0,1
1999 lxc.cgroup.cpu.shares = 1234
2000 lxc.cgroup.devices.deny = a
2001 lxc.cgroup.devices.allow = c 1:3 rw
2002 lxc.cgroup.devices.allow = b 8:0 rw
2003 </programlisting>
2004 </refsect2>
2005
2006 <refsect2>
2007 <title>Complex configuration</title>
2008 <para>This example show a complex configuration making a complex
2009 network stack, using the control groups, setting a new hostname,
2010 mounting some locations and a changing root file system.</para>
2011 <programlisting>
2012 lxc.uts.name = complex
2013 lxc.net.0.type = veth
2014 lxc.net.0.flags = up
2015 lxc.net.0.link = br0
2016 lxc.net.0.hwaddr = 4a:49:43:49:79:bf
2017 lxc.net.0.ipv4.address = 10.2.3.5/24 10.2.3.255
2018 lxc.net.0.ipv6.address = 2003:db8:1:0:214:1234:fe0b:3597
2019 lxc.net.0.ipv6.address = 2003:db8:1:0:214:5432:feab:3588
2020 lxc.net.1.type = macvlan
2021 lxc.net.1.flags = up
2022 lxc.net.1.link = eth0
2023 lxc.net.1.hwaddr = 4a:49:43:49:79:bd
2024 lxc.net.1.ipv4.address = 10.2.3.4/24
2025 lxc.net.1.ipv4.address = 192.168.10.125/24
2026 lxc.net.1.ipv6.address = 2003:db8:1:0:214:1234:fe0b:3596
2027 lxc.net.2.type = phys
2028 lxc.net.2.flags = up
2029 lxc.net.2.link = dummy0
2030 lxc.net.2.hwaddr = 4a:49:43:49:79:ff
2031 lxc.net.2.ipv4.address = 10.2.3.6/24
2032 lxc.net.2.ipv6.address = 2003:db8:1:0:214:1234:fe0b:3297
2033 lxc.cgroup.cpuset.cpus = 0,1
2034 lxc.cgroup.cpu.shares = 1234
2035 lxc.cgroup.devices.deny = a
2036 lxc.cgroup.devices.allow = c 1:3 rw
2037 lxc.cgroup.devices.allow = b 8:0 rw
2038 lxc.mount.fstab = /etc/fstab.complex
2039 lxc.mount.entry = /lib /root/myrootfs/lib none ro,bind 0 0
2040 lxc.rootfs.path = dir:/mnt/rootfs.complex
2041 lxc.cap.drop = sys_module mknod setuid net_raw
2042 lxc.cap.drop = mac_override
2043 </programlisting>
2044 </refsect2>
2045
2046 </refsect1>
2047
2048 <refsect1>
2049 <title>See Also</title>
2050 <simpara>
2051 <citerefentry>
2052 <refentrytitle><command>chroot</command></refentrytitle>
2053 <manvolnum>1</manvolnum>
2054 </citerefentry>,
2055
2056 <citerefentry>
2057 <refentrytitle><command>pivot_root</command></refentrytitle>
2058 <manvolnum>8</manvolnum>
2059 </citerefentry>,
2060
2061 <citerefentry>
2062 <refentrytitle><filename>fstab</filename></refentrytitle>
2063 <manvolnum>5</manvolnum>
2064 </citerefentry>,
2065
2066 <citerefentry>
2067 <refentrytitle><filename>capabilities</filename></refentrytitle>
2068 <manvolnum>7</manvolnum>
2069 </citerefentry>
2070 </simpara>
2071 </refsect1>
2072
2073 &seealso;
2074
2075 <refsect1>
2076 <title>Author</title>
2077 <para>Daniel Lezcano <email>daniel.lezcano@free.fr</email></para>
2078 </refsect1>
2079
2080 </refentry>
2081
2082 <!-- Keep this comment at the end of the file
2083 Local variables:
2084 mode: sgml
2085 sgml-omittag:t
2086 sgml-shorttag:t
2087 sgml-minimize-attributes:nil
2088 sgml-always-quote-attributes:t
2089 sgml-indent-step:2
2090 sgml-indent-data:t
2091 sgml-parent-document:nil
2092 sgml-default-dtd-file:nil
2093 sgml-exposed-tags:nil
2094 sgml-local-catalogs:nil
2095 sgml-local-ecat-files:nil
2096 End:
2097 -->