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