]> git.proxmox.com Git - mirror_lxc.git/blob - doc/lxc.container.conf.sgml.in
Merge pull request #3112 from avkvl/fix_count_user_network_interfaces
[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 support for 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 use 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 containers.
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>Proc</title>
343 <para>
344 Configure proc filesystem for the container.
345 </para>
346 <variablelist>
347 <varlistentry>
348 <term>
349 <option>lxc.proc.[proc file name]</option>
350 </term>
351 <listitem>
352 <para>
353 Specify the proc file name to be set. The file names available
354 are those listed under /proc/PID/.
355 Example:
356 </para>
357 <programlisting>
358 lxc.proc.oom_score_adj = 10
359 </programlisting>
360 </listitem>
361 </varlistentry>
362 </variablelist>
363 </refsect2>
364
365 <refsect2>
366 <title>Ephemeral</title>
367 <para>
368 Allows one to specify whether a container will be destroyed on shutdown.
369 </para>
370 <variablelist>
371 <varlistentry>
372 <term>
373 <option>lxc.ephemeral</option>
374 </term>
375 <listitem>
376 <para>
377 The only allowed values are 0 and 1. Set this to 1 to destroy a
378 container on shutdown.
379 </para>
380 </listitem>
381 </varlistentry>
382 </variablelist>
383 </refsect2>
384
385 <refsect2>
386 <title>Network</title>
387 <para>
388 The network section defines how the network is virtualized in
389 the container. The network virtualization acts at layer
390 two. In order to use the network virtualization, parameters
391 must be specified to define the network interfaces of the
392 container. Several virtual interfaces can be assigned and used
393 in a container even if the system has only one physical
394 network interface.
395 </para>
396 <variablelist>
397 <varlistentry>
398 <term>
399 <option>lxc.net</option>
400 </term>
401 <listitem>
402 <para>
403 may be used without a value to clear all previous network options.
404 </para>
405 </listitem>
406 </varlistentry>
407 <varlistentry>
408 <term>
409 <option>lxc.net.[i].type</option>
410 </term>
411 <listitem>
412 <para>
413 specify what kind of network virtualization to be used
414 for the container.
415 Multiple networks can be specified by using an additional index
416 <option>i</option>
417 after all <option>lxc.net.*</option> keys. For example,
418 <option>lxc.net.0.type = veth</option> and
419 <option>lxc.net.1.type = veth</option> specify two different
420 networks of the same type. All keys sharing the same index
421 <option>i</option> will be treated as belonging to the same
422 network. For example, <option>lxc.net.0.link = br0</option>
423 will belong to <option>lxc.net.0.type</option>.
424 Currently, the different virtualization types can be:
425 </para>
426
427 <para>
428 <option>none:</option> will cause the container to share
429 the host's network namespace. This means the host
430 network devices are usable in the container. It also
431 means that if both the container and host have upstart as
432 init, 'halt' in a container (for instance) will shut down the
433 host. Note that unprivileged containers do not work with this
434 setting due to an inability to mount sysfs. An unsafe workaround
435 would be to bind mount the host's sysfs.
436 </para>
437
438 <para>
439 <option>empty:</option> will create only the loopback
440 interface.
441 </para>
442
443 <para>
444 <option>veth:</option> a virtual ethernet pair
445 device is created with one side assigned to the container
446 and the other side on the host.
447 <option>lxc.net.[i].veth.mode</option> specifies the
448 mode the veth parent will use on the host.
449 The accepted modes are <option>bridge</option> and <option>router</option>.
450 The mode defaults to bridge if not specified.
451 In <option>bridge</option> mode the host side is attached to a bridge specified by
452 the <option>lxc.net.[i].link</option> option.
453 If the bridge link is not specified, then the veth pair device
454 will be created but not attached to any bridge.
455 Otherwise, the bridge has to be created on the system
456 before starting the container.
457 <command>lxc</command> won't handle any
458 configuration outside of the container.
459 In <option>router</option> mode static routes are created on the host for the
460 container's IP addresses pointing to the host side veth interface.
461 Additionally Proxy ARP and Proxy NDP entries are added on the host side veth interface
462 for the gateway IPs defined in the container to allow the container to reach the host.
463 By default, <command>lxc</command> chooses a name for the
464 network device belonging to the outside of the
465 container, but if you wish to handle
466 this name yourselves, you can tell <command>lxc</command>
467 to set a specific name with
468 the <option>lxc.net.[i].veth.pair</option> option (except for
469 unprivileged containers where this option is ignored for security
470 reasons).
471
472 Static routes can be added on the host pointing to the container using the
473 <option>lxc.net.[i].veth.ipv4.route</option> and
474 <option>lxc.net.[i].veth.ipv6.route</option> options.
475 Several lines specify several routes.
476 The route is in format x.y.z.t/m, eg. 192.168.1.0/24.
477 </para>
478
479 <para>
480 <option>vlan:</option> a vlan interface is linked with
481 the interface specified by
482 the <option>lxc.net.[i].link</option> and assigned to
483 the container. The vlan identifier is specified with the
484 option <option>lxc.net.[i].vlan.id</option>.
485 </para>
486
487 <para>
488 <option>macvlan:</option> a macvlan interface is linked
489 with the interface specified by
490 the <option>lxc.net.[i].link</option> and assigned to
491 the container.
492 <option>lxc.net.[i].macvlan.mode</option> specifies the
493 mode the macvlan will use to communicate between
494 different macvlan on the same upper device. The accepted
495 modes are <option>private</option>, <option>vepa</option>,
496 <option>bridge</option> and <option>passthru</option>.
497 In <option>private</option> mode, the device never
498 communicates with any other device on the same upper_dev (default).
499 In <option>vepa</option> mode, the new Virtual Ethernet Port
500 Aggregator (VEPA) mode, it assumes that the adjacent
501 bridge returns all frames where both source and
502 destination are local to the macvlan port, i.e. the
503 bridge is set up as a reflective relay. Broadcast
504 frames coming in from the upper_dev get flooded to all
505 macvlan interfaces in VEPA mode, local frames are not
506 delivered locally. In <option>bridge</option> mode, it
507 provides the behavior of a simple bridge between
508 different macvlan interfaces on the same port. Frames
509 from one interface to another one get delivered directly
510 and are not sent out externally. Broadcast frames get
511 flooded to all other bridge ports and to the external
512 interface, but when they come back from a reflective
513 relay, we don't deliver them again. Since we know all
514 the MAC addresses, the macvlan bridge mode does not
515 require learning or STP like the bridge module does. In
516 <option>passthru</option> mode, all frames received by
517 the physical interface are forwarded to the macvlan
518 interface. Only one macvlan interface in <option>passthru</option>
519 mode is possible for one physical interface.
520 </para>
521
522 <para>
523 <option>ipvlan:</option> an ipvlan interface is linked
524 with the interface specified by
525 the <option>lxc.net.[i].link</option> and assigned to
526 the container.
527 <option>lxc.net.[i].ipvlan.mode</option> specifies the
528 mode the ipvlan will use to communicate between
529 different ipvlan on the same upper device. The accepted
530 modes are <option>l3</option>, <option>l3s</option> and
531 <option>l2</option>. It defaults to <option>l3</option> mode.
532 In <option>l3</option> mode TX processing up to L3 happens on the stack instance
533 attached to the slave device and packets are switched to the stack instance of the
534 master device for the L2 processing and routing from that instance will be
535 used before packets are queued on the outbound device. In this mode the slaves
536 will not receive nor can send multicast / broadcast traffic.
537 In <option>l3s</option> mode TX processing is very similar to the L3 mode except that
538 iptables (conn-tracking) works in this mode and hence it is L3-symmetric (L3s).
539 This will have slightly less performance but that shouldn't matter since you are
540 choosing this mode over plain-L3 mode to make conn-tracking work.
541 In <option>l2</option> mode TX processing happens on the stack instance attached to
542 the slave device and packets are switched and queued to the master device to send
543 out. In this mode the slaves will RX/TX multicast and broadcast (if applicable) as well.
544 <option>lxc.net.[i].ipvlan.isolation</option> specifies the isolation mode.
545 The accepted isolation values are <option>bridge</option>,
546 <option>private</option> and <option>vepa</option>.
547 It defaults to <option>bridge</option>.
548 In <option>bridge</option> isolation mode slaves can cross-talk among themselves
549 apart from talking through the master device.
550 In <option>private</option> isolation mode the port is set in private mode.
551 i.e. port won't allow cross communication between slaves.
552 In <option>vepa</option> isolation mode the port is set in VEPA mode.
553 i.e. port will offload switching functionality to the external entity as
554 described in 802.1Qbg.
555 </para>
556
557 <para>
558 <option>phys:</option> an already existing interface
559 specified by the <option>lxc.net.[i].link</option> is
560 assigned to the container.
561 </para>
562 </listitem>
563 </varlistentry>
564
565 <varlistentry>
566 <term>
567 <option>lxc.net.[i].flags</option>
568 </term>
569 <listitem>
570 <para>
571 Specify an action to do for the network.
572 </para>
573
574 <para><option>up:</option> activates the interface.
575 </para>
576 </listitem>
577 </varlistentry>
578
579 <varlistentry>
580 <term>
581 <option>lxc.net.[i].link</option>
582 </term>
583 <listitem>
584 <para>
585 Specify the interface to be used for real network traffic.
586 </para>
587 </listitem>
588 </varlistentry>
589
590 <varlistentry>
591 <term>
592 <option>lxc.net.[i].l2proxy</option>
593 </term>
594 <listitem>
595 <para>
596 Controls whether layer 2 IP neighbour proxy entries will be added to the
597 lxc.net.[i].link interface for the IP addresses of the container.
598 Can be set to 0 or 1. Defaults to 0.
599 When used with IPv4 addresses, the following sysctl values need to be set:
600 net.ipv4.conf.[link].forwarding=1
601 When used with IPv6 addresses, the following sysctl values need to be set:
602 net.ipv6.conf.[link].proxy_ndp=1
603 net.ipv6.conf.[link].forwarding=1
604 </para>
605 </listitem>
606 </varlistentry>
607
608 <varlistentry>
609 <term>
610 <option>lxc.net.[i].mtu</option>
611 </term>
612 <listitem>
613 <para>
614 Specify the maximum transfer unit for this interface.
615 </para>
616 </listitem>
617 </varlistentry>
618
619 <varlistentry>
620 <term>
621 <option>lxc.net.[i].name</option>
622 </term>
623 <listitem>
624 <para>
625 The interface name is dynamically allocated, but if another name
626 is needed because the configuration files being used by the
627 container use a generic name, eg. eth0, this option will rename
628 the interface in the container.
629 </para>
630 </listitem>
631 </varlistentry>
632
633 <varlistentry>
634 <term>
635 <option>lxc.net.[i].hwaddr</option>
636 </term>
637 <listitem>
638 <para>
639 The interface mac address is dynamically allocated by default to
640 the virtual interface, but in some cases, this is needed to
641 resolve a mac address conflict or to always have the same
642 link-local ipv6 address. Any "x" in address will be replaced by
643 random value, this allows setting hwaddr templates.
644 </para>
645 </listitem>
646 </varlistentry>
647
648 <varlistentry>
649 <term>
650 <option>lxc.net.[i].ipv4.address</option>
651 </term>
652 <listitem>
653 <para>
654 Specify the ipv4 address to assign to the virtualized interface.
655 Several lines specify several ipv4 addresses. The address is in
656 format x.y.z.t/m, eg. 192.168.1.123/24.
657 </para>
658 </listitem>
659 </varlistentry>
660
661 <varlistentry>
662 <term>
663 <option>lxc.net.[i].ipv4.gateway</option>
664 </term>
665 <listitem>
666 <para>
667 Specify the ipv4 address to use as the gateway inside the
668 container. The address is in format x.y.z.t, eg. 192.168.1.123.
669
670 Can also have the special value <option>auto</option>,
671 which means to take the primary address from the bridge
672 interface (as specified by the
673 <option>lxc.net.[i].link</option> option) and use that as
674 the gateway. <option>auto</option> is only available when
675 using the <option>veth</option>,
676 <option>macvlan</option> and <option>ipvlan</option> network types.
677 Can also have the special value of <option>dev</option>,
678 which means to set the default gateway as a device route.
679 This is primarily for use with layer 3 network modes, such as IPVLAN.
680 </para>
681 </listitem>
682 </varlistentry>
683
684 <varlistentry>
685 <term>
686 <option>lxc.net.[i].ipv6.address</option>
687 </term>
688 <listitem>
689 <para>
690 Specify the ipv6 address to assign to the virtualized
691 interface. Several lines specify several ipv6 addresses. The
692 address is in format x::y/m, eg.
693 2003:db8:1:0:214:1234:fe0b:3596/64
694 </para>
695 </listitem>
696 </varlistentry>
697
698 <varlistentry>
699 <term>
700 <option>lxc.net.[i].ipv6.gateway</option>
701 </term>
702 <listitem>
703 <para>
704 Specify the ipv6 address to use as the gateway inside the
705 container. The address is in format x::y, eg. 2003:db8:1:0::1
706
707 Can also have the special value <option>auto</option>,
708 which means to take the primary address from the bridge
709 interface (as specified by the
710 <option>lxc.net.[i].link</option> option) and use that as
711 the gateway. <option>auto</option> is only available when
712 using the <option>veth</option>,
713 <option>macvlan</option> and <option>ipvlan</option> network types.
714 Can also have the special value of <option>dev</option>,
715 which means to set the default gateway as a device route.
716 This is primarily for use with layer 3 network modes, such as IPVLAN.
717 </para>
718 </listitem>
719 </varlistentry>
720
721 <varlistentry>
722 <term>
723 <option>lxc.net.[i].script.up</option>
724 </term>
725 <listitem>
726 <para>
727 Add a configuration option to specify a script to be
728 executed after creating and configuring the network used
729 from the host side.
730 </para>
731
732 <para>
733 In addition to the information available to all hooks. The
734 following information is provided to the script:
735 <itemizedlist>
736 <listitem>
737 <para>
738 LXC_HOOK_TYPE: the hook type. This is either 'up' or 'down'.
739 </para>
740 </listitem>
741
742 <listitem>
743 <para>
744 LXC_HOOK_SECTION: the section type 'net'.
745 </para>
746 </listitem>
747
748 <listitem>
749 <para>
750 LXC_NET_TYPE: the network type. This is one of the valid
751 network types listed here (e.g. 'vlan', 'macvlan', 'ipvlan', 'veth').
752 </para>
753 </listitem>
754
755 <listitem>
756 <para>
757 LXC_NET_PARENT: the parent device on the host. This is only
758 set for network types 'mavclan', 'veth', 'phys'.
759 </para>
760 </listitem>
761
762 <listitem>
763 <para>
764 LXC_NET_PEER: the name of the peer device on the host. This is
765 only set for 'veth' network types. Note that this information
766 is only available when <option>lxc.hook.version</option> is set
767 to 1.
768 </para>
769 </listitem>
770 </itemizedlist>
771
772 Whether this information is provided in the form of environment
773 variables or as arguments to the script depends on the value of
774 <option>lxc.hook.version</option>. If set to 1 then information is
775 provided in the form of environment variables. If set to 0
776 information is provided as arguments to the script.
777 </para>
778
779 <para>
780 Standard output from the script is logged at debug level.
781 Standard error is not logged, but can be captured by the
782 hook redirecting its standard error to standard output.
783 </para>
784 </listitem>
785 </varlistentry>
786
787 <varlistentry>
788 <term>
789 <option>lxc.net.[i].script.down</option>
790 </term>
791 <listitem>
792 <para>
793 Add a configuration option to specify a script to be
794 executed before destroying the network used from the
795 host side.
796 </para>
797
798 <para>
799 In addition to the information available to all hooks. The
800 following information is provided to the script:
801 <itemizedlist>
802 <listitem>
803 <para>
804 LXC_HOOK_TYPE: the hook type. This is either 'up' or 'down'.
805 </para>
806 </listitem>
807
808 <listitem>
809 <para>
810 LXC_HOOK_SECTION: the section type 'net'.
811 </para>
812 </listitem>
813
814 <listitem>
815 <para>
816 LXC_NET_TYPE: the network type. This is one of the valid
817 network types listed here (e.g. 'vlan', 'macvlan', 'ipvlan', 'veth').
818 </para>
819 </listitem>
820
821 <listitem>
822 <para>
823 LXC_NET_PARENT: the parent device on the host. This is only
824 set for network types 'mavclan', 'veth', 'phys'.
825 </para>
826 </listitem>
827
828 <listitem>
829 <para>
830 LXC_NET_PEER: the name of the peer device on the host. This is
831 only set for 'veth' network types. Note that this information
832 is only available when <option>lxc.hook.version</option> is set
833 to 1.
834 </para>
835 </listitem>
836 </itemizedlist>
837
838 Whether this information is provided in the form of environment
839 variables or as arguments to the script depends on the value of
840 <option>lxc.hook.version</option>. If set to 1 then information is
841 provided in the form of environment variables. If set to 0
842 information is provided as arguments to the script.
843 </para>
844
845 <para>
846 Standard output from the script is logged at debug level.
847 Standard error is not logged, but can be captured by the
848 hook redirecting its standard error to standard output.
849 </para>
850 </listitem>
851 </varlistentry>
852 </variablelist>
853 </refsect2>
854
855 <refsect2>
856 <title>New pseudo tty instance (devpts)</title>
857 <para>
858 For stricter isolation the container can have its own private
859 instance of the pseudo tty.
860 </para>
861 <variablelist>
862 <varlistentry>
863 <term>
864 <option>lxc.pty.max</option>
865 </term>
866 <listitem>
867 <para>
868 If set, the container will have a new pseudo tty
869 instance, making this private to it. The value specifies
870 the maximum number of pseudo ttys allowed for a pts
871 instance (this limitation is not implemented yet).
872 </para>
873 </listitem>
874 </varlistentry>
875 </variablelist>
876 </refsect2>
877
878 <refsect2>
879 <title>Container system console</title>
880 <para>
881 If the container is configured with a root filesystem and the
882 inittab file is setup to use the console, you may want to specify
883 where the output of this console goes.
884 </para>
885 <variablelist>
886
887 <varlistentry>
888 <term>
889 <option>lxc.console.buffer.size</option>
890 </term>
891 <listitem>
892 <para>
893 Setting this option instructs liblxc to allocate an in-memory
894 ringbuffer. The container's console output will be written to the
895 ringbuffer. Note that ringbuffer must be at least as big as a
896 standard page size. When passed a value smaller than a single page
897 size liblxc will allocate a ringbuffer of a single page size. A page
898 size is usually 4KB.
899
900 The keyword 'auto' will cause liblxc to allocate a ringbuffer of
901 128KB.
902
903 When manually specifying a size for the ringbuffer the value should
904 be a power of 2 when converted to bytes. Valid size prefixes are
905 'KB', 'MB', 'GB'. (Note that all conversions are based on multiples
906 of 1024. That means 'KB' == 'KiB', 'MB' == 'MiB', 'GB' == 'GiB'.
907 Additionally, the case of the suffix is ignored, i.e. 'kB', 'KB' and
908 'Kb' are treated equally.)
909 </para>
910 </listitem>
911 </varlistentry>
912
913 <varlistentry>
914 <term>
915 <option>lxc.console.size</option>
916 </term>
917 <listitem>
918 <para>
919 Setting this option instructs liblxc to place a limit on the size of
920 the console log file specified in
921 <option>lxc.console.logfile</option>. Note that size of the log file
922 must be at least as big as a standard page size. When passed a value
923 smaller than a single page size liblxc will set the size of log file
924 to a single page size. A page size is usually 4KB.
925
926 The keyword 'auto' will cause liblxc to place a limit of 128KB on
927 the log file.
928
929 When manually specifying a size for the log file the value should
930 be a power of 2 when converted to bytes. Valid size prefixes are
931 'KB', 'MB', 'GB'. (Note that all conversions are based on multiples
932 of 1024. That means 'KB' == 'KiB', 'MB' == 'MiB', 'GB' == 'GiB'.
933 Additionally, the case of the suffix is ignored, i.e. 'kB', 'KB' and
934 'Kb' are treated equally.)
935
936 If users want to mirror the console ringbuffer on disk they should set
937 <option>lxc.console.size</option> equal to
938 <option>lxc.console.buffer.size</option>.
939 </para>
940 </listitem>
941 </varlistentry>
942
943 <varlistentry>
944 <term>
945 <option>lxc.console.logfile</option>
946 </term>
947 <listitem>
948 <para>
949 Specify a path to a file where the console output will be written.
950 Note that in contrast to the on-disk ringbuffer logfile this file
951 will keep growing potentially filling up the users disks if not
952 rotated and deleted. This problem can also be avoided by using the
953 in-memory ringbuffer options
954 <option>lxc.console.buffer.size</option> and
955 <option>lxc.console.buffer.logfile</option>.
956 </para>
957 </listitem>
958 </varlistentry>
959
960 <varlistentry>
961 <term>
962 <option>lxc.console.rotate</option>
963 </term>
964 <listitem>
965 <para>
966 Whether to rotate the console logfile specified in
967 <option>lxc.console.logfile</option>. Users can send an API
968 request to rotate the logfile. Note that the old logfile will have
969 the same name as the original with the suffix ".1" appended.
970
971 Users wishing to prevent the console log file from filling the
972 disk should rotate the logfile and delete it if unneeded. This
973 problem can also be avoided by using the in-memory ringbuffer
974 options <option>lxc.console.buffer.size</option> and
975 <option>lxc.console.buffer.logfile</option>.
976 </para>
977 </listitem>
978 </varlistentry>
979
980 <varlistentry>
981 <term>
982 <option>lxc.console.path</option>
983 </term>
984 <listitem>
985 <para>
986 Specify a path to a device to which the console will be
987 attached. The keyword 'none' will simply disable the
988 console. Note, when specifying 'none' and creating a device node
989 for the console in the container at /dev/console or bind-mounting
990 the hosts's /dev/console into the container at /dev/console the
991 container will have direct access to the hosts's /dev/console.
992 This is dangerous when the container has write access to the
993 device and should thus be used with caution.
994 </para>
995 </listitem>
996 </varlistentry>
997 </variablelist>
998 </refsect2>
999
1000 <refsect2>
1001 <title>Console through the ttys</title>
1002 <para>
1003 This option is useful if the container is configured with a root
1004 filesystem and the inittab file is setup to launch a getty on the
1005 ttys. The option specifies the number of ttys to be available for
1006 the container. The number of gettys in the inittab file of the
1007 container should not be greater than the number of ttys specified
1008 in this option, otherwise the excess getty sessions will die and
1009 respawn indefinitely giving annoying messages on the console or in
1010 <filename>/var/log/messages</filename>.
1011 </para>
1012 <variablelist>
1013 <varlistentry>
1014 <term>
1015 <option>lxc.tty.max</option>
1016 </term>
1017 <listitem>
1018 <para>
1019 Specify the number of tty to make available to the
1020 container.
1021 </para>
1022 </listitem>
1023 </varlistentry>
1024 </variablelist>
1025 </refsect2>
1026
1027 <refsect2>
1028 <title>Console devices location</title>
1029 <para>
1030 LXC consoles are provided through Unix98 PTYs created on the
1031 host and bind-mounted over the expected devices in the container.
1032 By default, they are bind-mounted over <filename>/dev/console</filename>
1033 and <filename>/dev/ttyN</filename>. This can prevent package upgrades
1034 in the guest. Therefore you can specify a directory location (under
1035 <filename>/dev</filename> under which LXC will create the files and
1036 bind-mount over them. These will then be symbolically linked to
1037 <filename>/dev/console</filename> and <filename>/dev/ttyN</filename>.
1038 A package upgrade can then succeed as it is able to remove and replace
1039 the symbolic links.
1040 </para>
1041 <variablelist>
1042 <varlistentry>
1043 <term>
1044 <option>lxc.tty.dir</option>
1045 </term>
1046 <listitem>
1047 <para>
1048 Specify a directory under <filename>/dev</filename>
1049 under which to create the container console devices. Note that LXC
1050 will move any bind-mounts or device nodes for /dev/console into
1051 this directory.
1052 </para>
1053 </listitem>
1054 </varlistentry>
1055 </variablelist>
1056 </refsect2>
1057
1058 <refsect2>
1059 <title>/dev directory</title>
1060 <para>
1061 By default, lxc creates a few symbolic links (fd,stdin,stdout,stderr)
1062 in the container's <filename>/dev</filename> directory but does not
1063 automatically create device node entries. This allows the container's
1064 <filename>/dev</filename> to be set up as needed in the container
1065 rootfs. If lxc.autodev is set to 1, then after mounting the container's
1066 rootfs LXC will mount a fresh tmpfs under <filename>/dev</filename>
1067 (limited to 500k) and fill in a minimal set of initial devices.
1068 This is generally required when starting a container containing
1069 a "systemd" based "init" but may be optional at other times. Additional
1070 devices in the containers /dev directory may be created through the
1071 use of the <option>lxc.hook.autodev</option> hook.
1072 </para>
1073 <variablelist>
1074 <varlistentry>
1075 <term>
1076 <option>lxc.autodev</option>
1077 </term>
1078 <listitem>
1079 <para>
1080 Set this to 0 to stop LXC from mounting and populating a minimal
1081 <filename>/dev</filename> when starting the container.
1082 </para>
1083 </listitem>
1084 </varlistentry>
1085 </variablelist>
1086 </refsect2>
1087
1088 <refsect2>
1089 <title>Mount points</title>
1090 <para>
1091 The mount points section specifies the different places to be
1092 mounted. These mount points will be private to the container
1093 and won't be visible by the processes running outside of the
1094 container. This is useful to mount /etc, /var or /home for
1095 examples.
1096 </para>
1097 <para>
1098 NOTE - LXC will generally ensure that mount targets and relative
1099 bind-mount sources are properly confined under the container
1100 root, to avoid attacks involving over-mounting host directories
1101 and files. (Symbolic links in absolute mount sources are ignored)
1102 However, if the container configuration first mounts a directory which
1103 is under the control of the container user, such as /home/joe, into
1104 the container at some <filename>path</filename>, and then mounts
1105 under <filename>path</filename>, then a TOCTTOU attack would be
1106 possible where the container user modifies a symbolic link under
1107 his home directory at just the right time.
1108 </para>
1109 <variablelist>
1110 <varlistentry>
1111 <term>
1112 <option>lxc.mount.fstab</option>
1113 </term>
1114 <listitem>
1115 <para>
1116 specify a file location in
1117 the <filename>fstab</filename> format, containing the
1118 mount information. The mount target location can and in
1119 most cases should be a relative path, which will become
1120 relative to the mounted container root. For instance,
1121 </para>
1122 <programlisting>
1123 proc proc proc nodev,noexec,nosuid 0 0
1124 </programlisting>
1125 <para>
1126 Will mount a proc filesystem under the container's /proc,
1127 regardless of where the root filesystem comes from. This
1128 is resilient to block device backed filesystems as well as
1129 container cloning.
1130 </para>
1131 <para>
1132 Note that when mounting a filesystem from an
1133 image file or block device the third field (fs_vfstype)
1134 cannot be auto as with
1135 <citerefentry>
1136 <refentrytitle>mount</refentrytitle>
1137 <manvolnum>8</manvolnum>
1138 </citerefentry>
1139 but must be explicitly specified.
1140 </para>
1141 </listitem>
1142 </varlistentry>
1143
1144 <varlistentry>
1145 <term>
1146 <option>lxc.mount.entry</option>
1147 </term>
1148 <listitem>
1149 <para>
1150 Specify a mount point corresponding to a line in the
1151 fstab format.
1152
1153 Moreover lxc supports mount propagation, such as rslave or
1154 rprivate, and adds three additional mount options.
1155 <option>optional</option> don't fail if mount does not work.
1156 <option>create=dir</option> or <option>create=file</option>
1157 to create dir (or file) when the point will be mounted.
1158 <option>relative</option> source path is taken to be relative to
1159 the mounted container root. For instance,
1160 </para>
1161 <screen>
1162 dev/null proc/kcore none bind,relative 0 0
1163 </screen>
1164 <para>
1165 Will expand dev/null to ${<option>LXC_ROOTFS_MOUNT</option>}/dev/null,
1166 and mount it to proc/kcore inside the container.
1167 </para>
1168 </listitem>
1169 </varlistentry>
1170
1171 <varlistentry>
1172 <term>
1173 <option>lxc.mount.auto</option>
1174 </term>
1175 <listitem>
1176 <para>
1177 specify which standard kernel file systems should be
1178 automatically mounted. This may dramatically simplify
1179 the configuration. The file systems are:
1180 </para>
1181 <itemizedlist>
1182 <listitem>
1183 <para>
1184 <option>proc:mixed</option> (or <option>proc</option>):
1185 mount <filename>/proc</filename> as read-write, but
1186 remount <filename>/proc/sys</filename> and
1187 <filename>/proc/sysrq-trigger</filename> read-only
1188 for security / container isolation purposes.
1189 </para>
1190 </listitem>
1191 <listitem>
1192 <para>
1193 <option>proc:rw</option>: mount
1194 <filename>/proc</filename> as read-write
1195 </para>
1196 </listitem>
1197 <listitem>
1198 <para>
1199 <option>sys:mixed</option> (or <option>sys</option>):
1200 mount <filename>/sys</filename> as read-only but with
1201 /sys/devices/virtual/net writable.
1202 </para>
1203 </listitem>
1204 <listitem>
1205 <para>
1206 <option>sys:ro</option>:
1207 mount <filename>/sys</filename> as read-only
1208 for security / container isolation purposes.
1209 </para>
1210 </listitem>
1211 <listitem>
1212 <para>
1213 <option>sys:rw</option>: mount
1214 <filename>/sys</filename> as read-write
1215 </para>
1216 </listitem>
1217
1218 <listitem>
1219 <para>
1220 <option>cgroup:mixed</option>:
1221 Mount a tmpfs to <filename>/sys/fs/cgroup</filename>,
1222 create directories for all hierarchies to which the container
1223 is added, create subdirectories in those hierarchies with the
1224 name of the cgroup, and bind-mount the container's own cgroup
1225 into that directory. The container will be able to write to
1226 its own cgroup directory, but not the parents, since they will
1227 be remounted read-only.
1228 </para>
1229 </listitem>
1230
1231 <listitem>
1232 <para>
1233 <option>cgroup:mixed:force</option>:
1234 The <option>force</option> option will cause LXC to perform
1235 the cgroup mounts for the container under all circumstances.
1236 Otherwise it is similar to <option>cgroup:mixed</option>.
1237 This is mainly useful when the cgroup namespaces are enabled
1238 where LXC will normally leave mounting cgroups to the init
1239 binary of the container since it is perfectly safe to do so.
1240 </para>
1241 </listitem>
1242
1243 <listitem>
1244 <para>
1245 <option>cgroup:ro</option>:
1246 similar to <option>cgroup:mixed</option>, but everything will
1247 be mounted read-only.
1248 </para>
1249 </listitem>
1250
1251 <listitem>
1252 <para>
1253 <option>cgroup:ro:force</option>:
1254 The <option>force</option> option will cause LXC to perform
1255 the cgroup mounts for the container under all circumstances.
1256 Otherwise it is similar to <option>cgroup:ro</option>.
1257 This is mainly useful when the cgroup namespaces are enabled
1258 where LXC will normally leave mounting cgroups to the init
1259 binary of the container since it is perfectly safe to do so.
1260 </para>
1261 </listitem>
1262
1263 <listitem>
1264 <para>
1265 <option>cgroup:rw</option>: similar to
1266 <option>cgroup:mixed</option>, but everything will be mounted
1267 read-write. Note that the paths leading up to the container's
1268 own cgroup will be writable, but will not be a cgroup
1269 filesystem but just part of the tmpfs of
1270 <filename>/sys/fs/cgroup</filename>
1271 </para>
1272 </listitem>
1273
1274 <listitem>
1275 <para>
1276 <option>cgroup:rw:force</option>:
1277 The <option>force</option> option will cause LXC to perform
1278 the cgroup mounts for the container under all circumstances.
1279 Otherwise it is similar to <option>cgroup:rw</option>.
1280 This is mainly useful when the cgroup namespaces are enabled
1281 where LXC will normally leave mounting cgroups to the init
1282 binary of the container since it is perfectly safe to do so.
1283 </para>
1284 </listitem>
1285
1286 <listitem>
1287 <para>
1288 <option>cgroup</option> (without specifier):
1289 defaults to <option>cgroup:rw</option> if the
1290 container retains the CAP_SYS_ADMIN capability,
1291 <option>cgroup:mixed</option> otherwise.
1292 </para>
1293 </listitem>
1294
1295 <listitem>
1296 <para>
1297 <option>cgroup-full:mixed</option>:
1298 mount a tmpfs to <filename>/sys/fs/cgroup</filename>,
1299 create directories for all hierarchies to which
1300 the container is added, bind-mount the hierarchies
1301 from the host to the container and make everything
1302 read-only except the container's own cgroup. Note
1303 that compared to <option>cgroup</option>, where
1304 all paths leading up to the container's own cgroup
1305 are just simple directories in the underlying
1306 tmpfs, here
1307 <filename>/sys/fs/cgroup/$hierarchy</filename>
1308 will contain the host's full cgroup hierarchy,
1309 albeit read-only outside the container's own cgroup.
1310 This may leak quite a bit of information into the
1311 container.
1312 </para>
1313 </listitem>
1314
1315 <listitem>
1316 <para>
1317 <option>cgroup-full:mixed:force</option>:
1318 The <option>force</option> option will cause LXC to perform
1319 the cgroup mounts for the container under all circumstances.
1320 Otherwise it is similar to <option>cgroup-full:mixed</option>.
1321 This is mainly useful when the cgroup namespaces are enabled
1322 where LXC will normally leave mounting cgroups to the init
1323 binary of the container since it is perfectly safe to do so.
1324 </para>
1325 </listitem>
1326
1327 <listitem>
1328 <para>
1329 <option>cgroup-full:ro</option>: similar to
1330 <option>cgroup-full:mixed</option>, but everything
1331 will be mounted read-only.
1332 </para>
1333 </listitem>
1334
1335 <listitem>
1336 <para>
1337 <option>cgroup-full:ro:force</option>:
1338 The <option>force</option> option will cause LXC to perform
1339 the cgroup mounts for the container under all circumstances.
1340 Otherwise it is similar to <option>cgroup-full:ro</option>.
1341 This is mainly useful when the cgroup namespaces are enabled
1342 where LXC will normally leave mounting cgroups to the init
1343 binary of the container since it is perfectly safe to do so.
1344 </para>
1345 </listitem>
1346
1347 <listitem>
1348 <para>
1349 <option>cgroup-full:rw</option>: similar to
1350 <option>cgroup-full:mixed</option>, but everything
1351 will be mounted read-write. Note that in this case,
1352 the container may escape its own cgroup. (Note also
1353 that if the container has CAP_SYS_ADMIN support
1354 and can mount the cgroup filesystem itself, it may
1355 do so anyway.)
1356 </para>
1357 </listitem>
1358
1359 <listitem>
1360 <para>
1361 <option>cgroup-full:rw:force</option>:
1362 The <option>force</option> option will cause LXC to perform
1363 the cgroup mounts for the container under all circumstances.
1364 Otherwise it is similar to <option>cgroup-full:rw</option>.
1365 This is mainly useful when the cgroup namespaces are enabled
1366 where LXC will normally leave mounting cgroups to the init
1367 binary of the container since it is perfectly safe to do so.
1368 </para>
1369 </listitem>
1370
1371 <listitem>
1372 <para>
1373 <option>cgroup-full</option> (without specifier):
1374 defaults to <option>cgroup-full:rw</option> if the
1375 container retains the CAP_SYS_ADMIN capability,
1376 <option>cgroup-full:mixed</option> otherwise.
1377 </para>
1378 </listitem>
1379
1380 </itemizedlist>
1381 <para>
1382 If cgroup namespaces are enabled, then any <option>cgroup</option>
1383 auto-mounting request will be ignored, since the container can
1384 mount the filesystems itself, and automounting can confuse the
1385 container init.
1386 </para>
1387 <para>
1388 Note that if automatic mounting of the cgroup filesystem
1389 is enabled, the tmpfs under
1390 <filename>/sys/fs/cgroup</filename> will always be
1391 mounted read-write (but for the <option>:mixed</option>
1392 and <option>:ro</option> cases, the individual
1393 hierarchies,
1394 <filename>/sys/fs/cgroup/$hierarchy</filename>, will be
1395 read-only). This is in order to work around a quirk in
1396 Ubuntu's
1397 <citerefentry>
1398 <refentrytitle>mountall</refentrytitle>
1399 <manvolnum>8</manvolnum>
1400 </citerefentry>
1401 command that will cause containers to wait for user
1402 input at boot if
1403 <filename>/sys/fs/cgroup</filename> is mounted read-only
1404 and the container can't remount it read-write due to a
1405 lack of CAP_SYS_ADMIN.
1406 </para>
1407 <para>
1408 Examples:
1409 </para>
1410 <programlisting>
1411 lxc.mount.auto = proc sys cgroup
1412 lxc.mount.auto = proc:rw sys:rw cgroup-full:rw
1413 </programlisting>
1414 </listitem>
1415 </varlistentry>
1416
1417 </variablelist>
1418 </refsect2>
1419
1420 <refsect2>
1421 <title>Root file system</title>
1422 <para>
1423 The root file system of the container can be different than that
1424 of the host system.
1425 </para>
1426 <variablelist>
1427 <varlistentry>
1428 <term>
1429 <option>lxc.rootfs.path</option>
1430 </term>
1431 <listitem>
1432 <para>
1433 specify the root file system for the container. It can
1434 be an image file, a directory or a block device. If not
1435 specified, the container shares its root file system
1436 with the host.
1437 </para>
1438 <para>
1439 For directory or simple block-device backed containers,
1440 a pathname can be used. If the rootfs is backed by a nbd
1441 device, then <filename>nbd:file:1</filename> specifies that
1442 <filename>file</filename> should be attached to a nbd device,
1443 and partition 1 should be mounted as the rootfs.
1444 <filename>nbd:file</filename> specifies that the nbd device
1445 itself should be mounted. <filename>overlayfs:/lower:/upper</filename>
1446 specifies that the rootfs should be an overlay with <filename>/upper</filename>
1447 being mounted read-write over a read-only mount of <filename>/lower</filename>.
1448 For <filename>overlay</filename> multiple <filename>/lower</filename>
1449 directories can be specified. <filename>loop:/file</filename> tells lxc to attach
1450 <filename>/file</filename> to a loop device and mount the loop device.
1451 </para>
1452 </listitem>
1453 </varlistentry>
1454
1455 <varlistentry>
1456 <term>
1457 <option>lxc.rootfs.mount</option>
1458 </term>
1459 <listitem>
1460 <para>
1461 where to recursively bind <option>lxc.rootfs.path</option>
1462 before pivoting. This is to ensure success of the
1463 <citerefentry>
1464 <refentrytitle><command>pivot_root</command></refentrytitle>
1465 <manvolnum>8</manvolnum>
1466 </citerefentry>
1467 syscall. Any directory suffices, the default should
1468 generally work.
1469 </para>
1470 </listitem>
1471 </varlistentry>
1472
1473 <varlistentry>
1474 <term>
1475 <option>lxc.rootfs.options</option>
1476 </term>
1477 <listitem>
1478 <para>
1479 extra mount options to use when mounting the rootfs.
1480 </para>
1481 </listitem>
1482 </varlistentry>
1483
1484 <varlistentry>
1485 <term>
1486 <option>lxc.rootfs.managed</option>
1487 </term>
1488 <listitem>
1489 <para>
1490 Set this to 0 to indicate that LXC is not managing the
1491 container storage, then LXC will not modify the
1492 container storage. The default is 1.
1493 </para>
1494 </listitem>
1495 </varlistentry>
1496
1497 </variablelist>
1498 </refsect2>
1499
1500 <refsect2>
1501 <title>Control group</title>
1502 <para>
1503 The control group section contains the configuration for the
1504 different subsystem. <command>lxc</command> does not check the
1505 correctness of the subsystem name. This has the disadvantage
1506 of not detecting configuration errors until the container is
1507 started, but has the advantage of permitting any future
1508 subsystem.
1509 </para>
1510 <variablelist>
1511 <varlistentry>
1512 <term>
1513 <option>lxc.cgroup.[controller name]</option>
1514 </term>
1515 <listitem>
1516 <para>
1517 Specify the control group value to be set on a legacy cgroup
1518 hierarchy. The controller name is the literal name of the control
1519 group. The permitted names and the syntax of their values is not
1520 dictated by LXC, instead it depends on the features of the Linux
1521 kernel running at the time the container is started, eg.
1522 <option>lxc.cgroup.cpuset.cpus</option>
1523 </para>
1524 </listitem>
1525 </varlistentry>
1526 <varlistentry>
1527 <term>
1528 <option>lxc.cgroup2.[controller name]</option>
1529 </term>
1530 <listitem>
1531 <para>
1532 Specify the control group value to be set on the unified cgroup
1533 hierarchy. The controller name is the literal name of the control
1534 group. The permitted names and the syntax of their values is not
1535 dictated by LXC, instead it depends on the features of the Linux
1536 kernel running at the time the container is started, eg.
1537 <option>lxc.cgroup2.memory.high</option>
1538 </para>
1539 </listitem>
1540 </varlistentry>
1541 <varlistentry>
1542 <term>
1543 <option>lxc.cgroup.dir</option>
1544 </term>
1545 <listitem>
1546 <para>
1547 specify a directory or path in which the container's cgroup will
1548 be created. For example, setting
1549 <option>lxc.cgroup.dir = my-cgroup/first</option> for a container
1550 named "c1" will create the container's cgroup as a sub-cgroup of
1551 "my-cgroup". For example, if the user's current cgroup "my-user"
1552 is located in the root cgroup of the cpuset controller in a
1553 cgroup v1 hierarchy this would create the cgroup
1554 "/sys/fs/cgroup/cpuset/my-user/my-cgroup/first/c1" for the
1555 container. Any missing cgroups will be created by LXC. This
1556 presupposes that the user has write access to its current cgroup.
1557 </para>
1558 </listitem>
1559 </varlistentry>
1560 <varlistentry>
1561 <term>
1562 <option>lxc.cgroup.relative</option>
1563 </term>
1564 <listitem>
1565 <para>
1566 Set this to 1 to instruct LXC to never escape to the
1567 root cgroup. This makes it easy for users to adhere to
1568 restrictions enforced by cgroup2 and
1569 systemd. Specifically, this makes it possible to run LXC
1570 containers as systemd services.
1571 </para>
1572 </listitem>
1573 </varlistentry>
1574 </variablelist>
1575 </refsect2>
1576
1577 <refsect2>
1578 <title>Capabilities</title>
1579 <para>
1580 The capabilities can be dropped in the container if this one
1581 is run as root.
1582 </para>
1583 <variablelist>
1584 <varlistentry>
1585 <term>
1586 <option>lxc.cap.drop</option>
1587 </term>
1588 <listitem>
1589 <para>
1590 Specify the capability to be dropped in the container. A
1591 single line defining several capabilities with a space
1592 separation is allowed. The format is the lower case of
1593 the capability definition without the "CAP_" prefix,
1594 eg. CAP_SYS_MODULE should be specified as
1595 sys_module. See
1596 <citerefentry>
1597 <refentrytitle><command>capabilities</command></refentrytitle>
1598 <manvolnum>7</manvolnum>
1599 </citerefentry>.
1600 If used with no value, lxc will clear any drop capabilities
1601 specified up to this point.
1602 </para>
1603 </listitem>
1604 </varlistentry>
1605 <varlistentry>
1606 <term>
1607 <option>lxc.cap.keep</option>
1608 </term>
1609 <listitem>
1610 <para>
1611 Specify the capability to be kept in the container. All other
1612 capabilities will be dropped. When a special value of "none" is
1613 encountered, lxc will clear any keep capabilities specified up
1614 to this point. A value of "none" alone can be used to drop all
1615 capabilities.
1616 </para>
1617 </listitem>
1618 </varlistentry>
1619 </variablelist>
1620 </refsect2>
1621
1622 <refsect2>
1623 <title>Namespaces</title>
1624 <para>
1625 A namespace can be cloned (<option>lxc.namespace.clone</option>),
1626 kept (<option>lxc.namespace.keep</option>) or shared
1627 (<option>lxc.namespace.share.[namespace identifier]</option>).
1628 </para>
1629 <variablelist>
1630 <varlistentry>
1631 <term>
1632 <option>lxc.namespace.clone</option>
1633 </term>
1634 <listitem>
1635 <para>
1636 Specify namespaces which the container is supposed to be created
1637 with. The namespaces to create are specified as a space separated
1638 list. Each namespace must correspond to one of the standard
1639 namespace identifiers as seen in the
1640 <filename>/proc/PID/ns</filename> directory.
1641 When <option>lxc.namespace.clone</option> is not explicitly set all
1642 namespaces supported by the kernel and the current configuration
1643 will be used.
1644 </para>
1645
1646 <para>
1647 To create a new mount, net and ipc namespace set
1648 <option>lxc.namespace.clone=mount net ipc</option>.
1649 </para>
1650 </listitem>
1651 </varlistentry>
1652
1653 <varlistentry>
1654 <term>
1655 <option>lxc.namespace.keep</option>
1656 </term>
1657 <listitem>
1658 <para>
1659 Specify namespaces which the container is supposed to inherit from
1660 the process that created it. The namespaces to keep are specified as
1661 a space separated list. Each namespace must correspond to one of the
1662 standard namespace identifiers as seen in the
1663 <filename>/proc/PID/ns</filename> directory.
1664 The <option>lxc.namespace.keep</option> is a
1665 blacklist option, i.e. it is useful when enforcing that containers
1666 must keep a specific set of namespaces.
1667 </para>
1668
1669 <para>
1670 To keep the network, user and ipc namespace set
1671 <option>lxc.namespace.keep=user net ipc</option>.
1672 </para>
1673
1674 <para>
1675 Note that sharing pid namespaces will likely not work with most init
1676 systems.
1677 </para>
1678
1679 <para>
1680 Note that if the container requests a new user namespace and the
1681 container wants to inherit the network namespace it needs to inherit
1682 the user namespace as well.
1683 </para>
1684 </listitem>
1685 </varlistentry>
1686
1687 <varlistentry>
1688 <term>
1689 <option>lxc.namespace.share.[namespace identifier]</option>
1690 </term>
1691 <listitem>
1692 <para>
1693 Specify a namespace to inherit from another container or process.
1694 The <option>[namespace identifier]</option> suffix needs to be
1695 replaced with one of the namespaces that appear in the
1696 <filename>/proc/PID/ns</filename> directory.
1697 </para>
1698
1699 <para>
1700 To inherit the namespace from another process set the
1701 <option>lxc.namespace.share.[namespace identifier]</option> to the PID of
1702 the process, e.g. <option>lxc.namespace.share.net=42</option>.
1703 </para>
1704
1705 <para>
1706 To inherit the namespace from another container set the
1707 <option>lxc.namespace.share.[namespace identifier]</option> to the name of
1708 the container, e.g. <option>lxc.namespace.share.pid=c3</option>.
1709 </para>
1710
1711 <para>
1712 To inherit the namespace from another container located in a
1713 different path than the standard liblxc path set the
1714 <option>lxc.namespace.share.[namespace identifier]</option> to the full
1715 path to the container, e.g.
1716 <option>lxc.namespace.share.user=/opt/c3</option>.
1717 </para>
1718
1719 <para>
1720 In order to inherit namespaces the caller needs to have sufficient
1721 privilege over the process or container.
1722 </para>
1723
1724 <para>
1725 Note that sharing pid namespaces between system containers will
1726 likely not work with most init systems.
1727 </para>
1728
1729 <para>
1730 Note that if two processes are in different user namespaces and one
1731 process wants to inherit the other's network namespace it usually
1732 needs to inherit the user namespace as well.
1733 </para>
1734
1735 <para>
1736 Note that without careful additional configuration of an LSM,
1737 sharing user+pid namespaces with a task may allow that task to
1738 escalate privileges to that of the task calling liblxc.
1739 </para>
1740 </listitem>
1741 </varlistentry>
1742 </variablelist>
1743 </refsect2>
1744
1745 <refsect2>
1746 <title>Resource limits</title>
1747 <para>
1748 The soft and hard resource limits for the container can be changed.
1749 Unprivileged containers can only lower them. Resources which are not
1750 explicitly specified will be inherited.
1751 </para>
1752 <variablelist>
1753 <varlistentry>
1754 <term>
1755 <option>lxc.prlimit.[limit name]</option>
1756 </term>
1757 <listitem>
1758 <para>
1759 Specify the resource limit to be set. A limit is specified as two
1760 colon separated values which are either numeric or the word
1761 'unlimited'. A single value can be used as a shortcut to set both
1762 soft and hard limit to the same value. The permitted names the
1763 "RLIMIT_" resource names in lowercase without the "RLIMIT_"
1764 prefix, eg. RLIMIT_NOFILE should be specified as "nofile". See
1765 <citerefentry>
1766 <refentrytitle><command>setrlimit</command></refentrytitle>
1767 <manvolnum>2</manvolnum>
1768 </citerefentry>.
1769 If used with no value, lxc will clear the resource limit
1770 specified up to this point. A resource with no explicitly
1771 configured limitation will be inherited from the process starting
1772 up the container.
1773 </para>
1774 </listitem>
1775 </varlistentry>
1776 </variablelist>
1777 </refsect2>
1778
1779 <refsect2>
1780 <title>Sysctl</title>
1781 <para>
1782 Configure kernel parameters for the container.
1783 </para>
1784 <variablelist>
1785 <varlistentry>
1786 <term>
1787 <option>lxc.sysctl.[kernel parameters name]</option>
1788 </term>
1789 <listitem>
1790 <para>
1791 Specify the kernel parameters to be set. The parameters available
1792 are those listed under /proc/sys/.
1793 Note that not all sysctls are namespaced. Changing Non-namespaced
1794 sysctls will cause the system-wide setting to be modified.
1795 <citerefentry>
1796 <refentrytitle><command>sysctl</command></refentrytitle>
1797 <manvolnum>8</manvolnum>
1798 </citerefentry>.
1799 If used with no value, lxc will clear the parameters specified up
1800 to this point.
1801 </para>
1802 </listitem>
1803 </varlistentry>
1804 </variablelist>
1805 </refsect2>
1806
1807 <refsect2>
1808 <title>Apparmor profile</title>
1809 <para>
1810 If lxc was compiled and installed with apparmor support, and the host
1811 system has apparmor enabled, then the apparmor profile under which the
1812 container should be run can be specified in the container
1813 configuration. The default is <command>lxc-container-default-cgns</command>
1814 if the host kernel is cgroup namespace aware, or
1815 <command>lxc-container-default</command> otherwise.
1816 </para>
1817 <variablelist>
1818 <varlistentry>
1819 <term>
1820 <option>lxc.apparmor.profile</option>
1821 </term>
1822 <listitem>
1823 <para>
1824 Specify the apparmor profile under which the container should
1825 be run. To specify that the container should be unconfined,
1826 use
1827 </para>
1828 <programlisting>lxc.apparmor.profile = unconfined</programlisting>
1829 <para>
1830 If the apparmor profile should remain unchanged (i.e. if you
1831 are nesting containers and are already confined), then use
1832 </para>
1833 <programlisting>lxc.apparmor.profile = unchanged</programlisting>
1834 <para>
1835 If you instruct LXC to generate the apparmor profile,
1836 then use
1837 </para>
1838 <programlisting>lxc.apparmor.profile = generated</programlisting>
1839 </listitem>
1840 </varlistentry>
1841 <varlistentry>
1842 <term>
1843 <option>lxc.apparmor.allow_incomplete</option>
1844 </term>
1845 <listitem>
1846 <para>
1847 Apparmor profiles are pathname based. Therefore many file
1848 restrictions require mount restrictions to be effective against
1849 a determined attacker. However, these mount restrictions are not
1850 yet implemented in the upstream kernel. Without the mount
1851 restrictions, the apparmor profiles still protect against accidental
1852 damager.
1853 </para>
1854 <para>
1855 If this flag is 0 (default), then the container will not be
1856 started if the kernel lacks the apparmor mount features, so that a
1857 regression after a kernel upgrade will be detected. To start the
1858 container under partial apparmor protection, set this flag to 1.
1859 </para>
1860 </listitem>
1861 </varlistentry>
1862
1863 <varlistentry>
1864 <term>
1865 <option>lxc.apparmor.allow_nesting</option>
1866 </term>
1867 <listitem>
1868 <para>
1869 If set this to 1, causes the following changes. When
1870 generated apparmor profiles are used, they will contain
1871 the necessary changes to allow creating a nested
1872 container. In addition to the usual mount points,
1873 <filename>/dev/.lxc/proc</filename>
1874 and <filename>/dev/.lxc/sys</filename> will contain
1875 procfs and sysfs mount points without the lxcfs
1876 overlays, which, if generated apparmor profiles are
1877 being used, will not be read/writable directly.
1878 </para>
1879 </listitem>
1880 </varlistentry>
1881
1882 <varlistentry>
1883 <term>
1884 <option>lxc.apparmor.raw</option>
1885 </term>
1886 <listitem>
1887 <para>
1888 A list of raw AppArmor profile lines to append to the
1889 profile. Only valid when using generated profiles.
1890 </para>
1891 </listitem>
1892 </varlistentry>
1893
1894 </variablelist>
1895 </refsect2>
1896
1897 <refsect2>
1898 <title>SELinux context</title>
1899 <para>
1900 If lxc was compiled and installed with SELinux support, and the host
1901 system has SELinux enabled, then the SELinux context under which the
1902 container should be run can be specified in the container
1903 configuration. The default is <command>unconfined_t</command>,
1904 which means that lxc will not attempt to change contexts.
1905 See @DATADIR@/lxc/selinux/lxc.te for an example policy and more
1906 information.
1907 </para>
1908 <variablelist>
1909 <varlistentry>
1910 <term>
1911 <option>lxc.selinux.context</option>
1912 </term>
1913 <listitem>
1914 <para>
1915 Specify the SELinux context under which the container should
1916 be run or <command>unconfined_t</command>. For example
1917 </para>
1918 <programlisting>lxc.selinux.context = system_u:system_r:lxc_t:s0:c22</programlisting>
1919 </listitem>
1920 </varlistentry>
1921 </variablelist>
1922 </refsect2>
1923
1924 <refsect2>
1925 <title>Seccomp configuration</title>
1926 <para>
1927 A container can be started with a reduced set of available
1928 system calls by loading a seccomp profile at startup. The
1929 seccomp configuration file must begin with a version number
1930 on the first line, a policy type on the second line, followed
1931 by the configuration.
1932 </para>
1933 <para>
1934 Versions 1 and 2 are currently supported. In version 1, the
1935 policy is a simple whitelist. The second line therefore must
1936 read "whitelist", with the rest of the file containing one (numeric)
1937 syscall number per line. Each syscall number is whitelisted,
1938 while every unlisted number is blacklisted for use in the container
1939 </para>
1940
1941 <para>
1942 In version 2, the policy may be blacklist or whitelist,
1943 supports per-rule and per-policy default actions, and supports
1944 per-architecture system call resolution from textual names.
1945 </para>
1946 <para>
1947 An example blacklist policy, in which all system calls are
1948 allowed except for mknod, which will simply do nothing and
1949 return 0 (success), looks like:
1950 </para>
1951
1952 <programlisting>
1953 2
1954 blacklist
1955 mknod errno 0
1956 ioctl notify
1957 </programlisting>
1958
1959 <para>
1960 Specifying "errno" as action will cause LXC to register a seccomp filter
1961 that will cause a specific errno to be returned to the caller. The errno
1962 value can be specified after the "errno" action word.
1963 </para>
1964
1965 <para>
1966 Specifying "notify" as action will cause LXC to register a seccomp
1967 listener and retrieve a listener file descriptor from the kernel. When a
1968 syscall is made that is registered as "notify" the kernel will generate a
1969 poll event and send a message over the file descriptor. The caller can
1970 read this message, inspect the syscalls including its arguments. Based on
1971 this information the caller is expected to send back a message informing
1972 the kernel which action to take. Until that message is sent the kernel
1973 will block the calling process. The format of the messages to read and
1974 sent is documented in seccomp itself.
1975 </para>
1976
1977 <variablelist>
1978 <varlistentry>
1979 <term>
1980 <option>lxc.seccomp.profile</option>
1981 </term>
1982 <listitem>
1983 <para>
1984 Specify a file containing the seccomp configuration to
1985 load before the container starts.
1986 </para>
1987 </listitem>
1988 </varlistentry>
1989 <varlistentry>
1990 <term>
1991 <option>lxc.seccomp.allow_nesting</option>
1992 </term>
1993 <listitem>
1994 <para>
1995 If this flag is set to 1, then seccomp filters will be stacked
1996 regardless of whether a seccomp profile is already loaded.
1997 This allows nested containers to load their own seccomp profile.
1998 The default setting is 0.
1999 </para>
2000 </listitem>
2001 </varlistentry>
2002 <varlistentry>
2003 <term>
2004 <option>lxc.seccomp.notify.proxy</option>
2005 </term>
2006 <listitem>
2007 <para>
2008 Specify a unix socket to which LXC will connect and forward
2009 seccomp events to. The path must be in the form
2010 unix:/path/to/socket or unix:@socket. The former specifies a
2011 path-bound unix domain socket while the latter specifies an
2012 abstract unix domain socket.
2013 </para>
2014 </listitem>
2015 </varlistentry>
2016 <varlistentry>
2017 <term>
2018 <option>lxc.seccomp.notify.cookie</option>
2019 </term>
2020 <listitem>
2021 <para>
2022 An additional string sent along with proxied seccomp notification
2023 requests.
2024 </para>
2025 </listitem>
2026 </varlistentry>
2027 </variablelist>
2028 </refsect2>
2029
2030 <refsect2>
2031 <title>PR_SET_NO_NEW_PRIVS</title>
2032 <para>
2033 With PR_SET_NO_NEW_PRIVS active execve() promises not to grant
2034 privileges to do anything that could not have been done without
2035 the execve() call (for example, rendering the set-user-ID and
2036 set-group-ID mode bits, and file capabilities non-functional).
2037 Once set, this bit cannot be unset. The setting of this bit is
2038 inherited by children created by fork() and clone(), and preserved
2039 across execve().
2040 Note that PR_SET_NO_NEW_PRIVS is applied after the container has
2041 changed into its intended AppArmor profile or SElinux context.
2042 </para>
2043 <variablelist>
2044 <varlistentry>
2045 <term>
2046 <option>lxc.no_new_privs</option>
2047 </term>
2048 <listitem>
2049 <para>
2050 Specify whether the PR_SET_NO_NEW_PRIVS flag should be set for the
2051 container. Set to 1 to activate.
2052 </para>
2053 </listitem>
2054 </varlistentry>
2055 </variablelist>
2056 </refsect2>
2057
2058 <refsect2>
2059 <title>UID mappings</title>
2060 <para>
2061 A container can be started in a private user namespace with
2062 user and group id mappings. For instance, you can map userid
2063 0 in the container to userid 200000 on the host. The root
2064 user in the container will be privileged in the container,
2065 but unprivileged on the host. Normally a system container
2066 will want a range of ids, so you would map, for instance,
2067 user and group ids 0 through 20,000 in the container to the
2068 ids 200,000 through 220,000.
2069 </para>
2070 <variablelist>
2071 <varlistentry>
2072 <term>
2073 <option>lxc.idmap</option>
2074 </term>
2075 <listitem>
2076 <para>
2077 Four values must be provided. First a character, either
2078 'u', or 'g', to specify whether user or group ids are
2079 being mapped. Next is the first userid as seen in the
2080 user namespace of the container. Next is the userid as
2081 seen on the host. Finally, a range indicating the number
2082 of consecutive ids to map.
2083 </para>
2084 </listitem>
2085 </varlistentry>
2086 </variablelist>
2087 </refsect2>
2088
2089 <refsect2>
2090 <title>Container hooks</title>
2091 <para>
2092 Container hooks are programs or scripts which can be executed
2093 at various times in a container's lifetime.
2094 </para>
2095 <para>
2096 When a container hook is executed, additional information is passed
2097 along. The <option>lxc.hook.version</option> argument can be used to
2098 determine if the following arguments are passed as command line
2099 arguments or through environment variables. The arguments are:
2100 <itemizedlist>
2101 <listitem><para> Container name. </para></listitem>
2102 <listitem><para> Section (always 'lxc'). </para></listitem>
2103 <listitem><para> The hook type (i.e. 'clone' or 'pre-mount'). </para></listitem>
2104 <listitem><para> Additional arguments. In the
2105 case of the clone hook, any extra arguments passed will appear as
2106 further arguments to the hook. In the case of the stop hook, paths to
2107 filedescriptors for each of the container's namespaces along with
2108 their types are passed. </para></listitem>
2109 </itemizedlist>
2110 The following environment variables are set:
2111 <itemizedlist>
2112 <listitem><para> LXC_CGNS_AWARE: indicator whether the container is
2113 cgroup namespace aware. </para></listitem>
2114 <listitem><para> LXC_CONFIG_FILE: the path to the container
2115 configuration file. </para></listitem>
2116 <listitem><para> LXC_HOOK_TYPE: the hook type (e.g. 'clone', 'mount',
2117 'pre-mount'). Note that the existence of this environment variable is
2118 conditional on the value of <option>lxc.hook.version</option>. If it
2119 is set to 1 then LXC_HOOK_TYPE will be set.
2120 </para></listitem>
2121 <listitem><para> LXC_HOOK_SECTION: the section type (e.g. 'lxc',
2122 'net'). Note that the existence of this environment variable is
2123 conditional on the value of <option>lxc.hook.version</option>. If it
2124 is set to 1 then LXC_HOOK_SECTION will be set.
2125 </para></listitem>
2126 <listitem><para> LXC_HOOK_VERSION: the version of the hooks. This
2127 value is identical to the value of the container's
2128 <option>lxc.hook.version</option> config item. If it is set to 0 then
2129 old-style hooks are used. If it is set to 1 then new-style hooks are
2130 used. </para></listitem>
2131 <listitem><para> LXC_LOG_LEVEL: the container's log level. </para></listitem>
2132 <listitem><para> LXC_NAME: is the container's name. </para></listitem>
2133 <listitem><para> LXC_[NAMESPACE IDENTIFIER]_NS: path under
2134 /proc/PID/fd/ to a file descriptor referring to the container's
2135 namespace. For each preserved namespace type there will be a separate
2136 environment variable. These environment variables will only be set if
2137 <option>lxc.hook.version</option> is set to 1. </para></listitem>
2138 <listitem><para> LXC_ROOTFS_MOUNT: the path to the mounted root filesystem. </para></listitem>
2139 <listitem><para> LXC_ROOTFS_PATH: this is the lxc.rootfs.path entry
2140 for the container. Note this is likely not where the mounted rootfs is
2141 to be found, use LXC_ROOTFS_MOUNT for that. </para></listitem>
2142 <listitem><para> LXC_SRC_NAME: in the case of the clone hook, this is
2143 the original container's name. </para></listitem>
2144 </itemizedlist>
2145 </para>
2146 <para>
2147 Standard output from the hooks is logged at debug level.
2148 Standard error is not logged, but can be captured by the
2149 hook redirecting its standard error to standard output.
2150 </para>
2151 <variablelist>
2152 <varlistentry>
2153 <term>
2154 <option>lxc.hook.version</option>
2155 </term>
2156 <listitem>
2157 <para>
2158 To pass the arguments in new style via environment variables set to
2159 1 otherwise set to 0 to pass them as arguments.
2160 This setting affects all hooks arguments that were traditionally
2161 passed as arguments to the script. Specifically, it affects the
2162 container name, section (e.g. 'lxc', 'net') and hook type (e.g.
2163 'clone', 'mount', 'pre-mount') arguments. If new-style hooks are
2164 used then the arguments will be available as environment variables.
2165 The container name will be set in LXC_NAME. (This is set
2166 independently of the value used for this config item.) The section
2167 will be set in LXC_HOOK_SECTION and the hook type will be set in
2168 LXC_HOOK_TYPE.
2169 It also affects how the paths to file descriptors referring to the
2170 container's namespaces are passed. If set to 1 then for each
2171 namespace a separate environment variable LXC_[NAMESPACE
2172 IDENTIFIER]_NS will be set. If set to 0 then the paths will be
2173 passed as arguments to the stop hook.
2174 </para>
2175 </listitem>
2176 </varlistentry>
2177 </variablelist>
2178 <variablelist>
2179 <varlistentry>
2180 <term>
2181 <option>lxc.hook.pre-start</option>
2182 </term>
2183 <listitem>
2184 <para>
2185 A hook to be run in the host's namespace before the
2186 container ttys, consoles, or mounts are up.
2187 </para>
2188 </listitem>
2189 </varlistentry>
2190 </variablelist>
2191 <variablelist>
2192 <varlistentry>
2193 <term>
2194 <option>lxc.hook.pre-mount</option>
2195 </term>
2196 <listitem>
2197 <para>
2198 A hook to be run in the container's fs namespace but before
2199 the rootfs has been set up. This allows for manipulation
2200 of the rootfs, i.e. to mount an encrypted filesystem. Mounts
2201 done in this hook will not be reflected on the host (apart from
2202 mounts propagation), so they will be automatically cleaned up
2203 when the container shuts down.
2204 </para>
2205 </listitem>
2206 </varlistentry>
2207 </variablelist>
2208 <variablelist>
2209 <varlistentry>
2210 <term>
2211 <option>lxc.hook.mount</option>
2212 </term>
2213 <listitem>
2214 <para>
2215 A hook to be run in the container's namespace after
2216 mounting has been done, but before the pivot_root.
2217 </para>
2218 </listitem>
2219 </varlistentry>
2220 </variablelist>
2221 <variablelist>
2222 <varlistentry>
2223 <term>
2224 <option>lxc.hook.autodev</option>
2225 </term>
2226 <listitem>
2227 <para>
2228 A hook to be run in the container's namespace after
2229 mounting has been done and after any mount hooks have
2230 run, but before the pivot_root, if
2231 <option>lxc.autodev</option> == 1.
2232 The purpose of this hook is to assist in populating the
2233 /dev directory of the container when using the autodev
2234 option for systemd based containers. The container's /dev
2235 directory is relative to the
2236 ${<option>LXC_ROOTFS_MOUNT</option>} environment
2237 variable available when the hook is run.
2238 </para>
2239 </listitem>
2240 </varlistentry>
2241 </variablelist>
2242 <variablelist>
2243 <varlistentry>
2244 <term>
2245 <option>lxc.hook.start-host</option>
2246 </term>
2247 <listitem>
2248 <para>
2249 A hook to be run in the host's namespace after the
2250 container has been setup, and immediately before starting
2251 the container init.
2252 </para>
2253 </listitem>
2254 </varlistentry>
2255 </variablelist>
2256 <variablelist>
2257 <varlistentry>
2258 <term>
2259 <option>lxc.hook.start</option>
2260 </term>
2261 <listitem>
2262 <para>
2263 A hook to be run in the container's namespace immediately
2264 before executing the container's init. This requires the
2265 program to be available in the container.
2266 </para>
2267 </listitem>
2268 </varlistentry>
2269 </variablelist>
2270 <variablelist>
2271 <varlistentry>
2272 <term>
2273 <option>lxc.hook.stop</option>
2274 </term>
2275 <listitem>
2276 <para>
2277 A hook to be run in the host's namespace with references
2278 to the container's namespaces after the container has been shut
2279 down. For each namespace an extra argument is passed to the hook
2280 containing the namespace's type and a filename that can be used to
2281 obtain a file descriptor to the corresponding namespace, separated
2282 by a colon. The type is the name as it would appear in the
2283 <filename>/proc/PID/ns</filename> directory.
2284 For instance for the mount namespace the argument usually looks
2285 like <filename>mnt:/proc/PID/fd/12</filename>.
2286 </para>
2287 </listitem>
2288 </varlistentry>
2289 </variablelist>
2290 <variablelist>
2291 <varlistentry>
2292 <term>
2293 <option>lxc.hook.post-stop</option>
2294 </term>
2295 <listitem>
2296 <para>
2297 A hook to be run in the host's namespace after the
2298 container has been shut down.
2299 </para>
2300 </listitem>
2301 </varlistentry>
2302 </variablelist>
2303 <variablelist>
2304 <varlistentry>
2305 <term>
2306 <option>lxc.hook.clone</option>
2307 </term>
2308 <listitem>
2309 <para>
2310 A hook to be run when the container is cloned to a new one.
2311 See <citerefentry><refentrytitle><command>lxc-clone</command></refentrytitle>
2312 <manvolnum>1</manvolnum></citerefentry> for more information.
2313 </para>
2314 </listitem>
2315 </varlistentry>
2316 </variablelist>
2317 <variablelist>
2318 <varlistentry>
2319 <term>
2320 <option>lxc.hook.destroy</option>
2321 </term>
2322 <listitem>
2323 <para>
2324 A hook to be run when the container is destroyed.
2325 </para>
2326 </listitem>
2327 </varlistentry>
2328 </variablelist>
2329 </refsect2>
2330
2331 <refsect2>
2332 <title>Container hooks Environment Variables</title>
2333 <para>
2334 A number of environment variables are made available to the startup
2335 hooks to provide configuration information and assist in the
2336 functioning of the hooks. Not all variables are valid in all
2337 contexts. In particular, all paths are relative to the host system
2338 and, as such, not valid during the <option>lxc.hook.start</option> hook.
2339 </para>
2340 <variablelist>
2341 <varlistentry>
2342 <term>
2343 <option>LXC_NAME</option>
2344 </term>
2345 <listitem>
2346 <para>
2347 The LXC name of the container. Useful for logging messages
2348 in common log environments. [<option>-n</option>]
2349 </para>
2350 </listitem>
2351 </varlistentry>
2352 </variablelist>
2353 <variablelist>
2354 <varlistentry>
2355 <term>
2356 <option>LXC_CONFIG_FILE</option>
2357 </term>
2358 <listitem>
2359 <para>
2360 Host relative path to the container configuration file. This
2361 gives the container to reference the original, top level,
2362 configuration file for the container in order to locate any
2363 additional configuration information not otherwise made
2364 available. [<option>-f</option>]
2365 </para>
2366 </listitem>
2367 </varlistentry>
2368 </variablelist>
2369 <variablelist>
2370 <varlistentry>
2371 <term>
2372 <option>LXC_CONSOLE</option>
2373 </term>
2374 <listitem>
2375 <para>
2376 The path to the console output of the container if not NULL.
2377 [<option>-c</option>] [<option>lxc.console.path</option>]
2378 </para>
2379 </listitem>
2380 </varlistentry>
2381 </variablelist>
2382 <variablelist>
2383 <varlistentry>
2384 <term>
2385 <option>LXC_CONSOLE_LOGPATH</option>
2386 </term>
2387 <listitem>
2388 <para>
2389 The path to the console log output of the container if not NULL.
2390 [<option>-L</option>]
2391 </para>
2392 </listitem>
2393 </varlistentry>
2394 </variablelist>
2395 <variablelist>
2396 <varlistentry>
2397 <term>
2398 <option>LXC_ROOTFS_MOUNT</option>
2399 </term>
2400 <listitem>
2401 <para>
2402 The mount location to which the container is initially bound.
2403 This will be the host relative path to the container rootfs
2404 for the container instance being started and is where changes
2405 should be made for that instance.
2406 [<option>lxc.rootfs.mount</option>]
2407 </para>
2408 </listitem>
2409 </varlistentry>
2410 </variablelist>
2411 <variablelist>
2412 <varlistentry>
2413 <term>
2414 <option>LXC_ROOTFS_PATH</option>
2415 </term>
2416 <listitem>
2417 <para>
2418 The host relative path to the container root which has been
2419 mounted to the rootfs.mount location.
2420 [<option>lxc.rootfs.path</option>]
2421 </para>
2422 </listitem>
2423 </varlistentry>
2424 </variablelist>
2425 <variablelist>
2426 <varlistentry>
2427 <term>
2428 <option>LXC_SRC_NAME</option>
2429 </term>
2430 <listitem>
2431 <para>
2432 Only for the clone hook. Is set to the original container name.
2433 </para>
2434 </listitem>
2435 </varlistentry>
2436 </variablelist>
2437 <variablelist>
2438 <varlistentry>
2439 <term>
2440 <option>LXC_TARGET</option>
2441 </term>
2442 <listitem>
2443 <para>
2444 Only for the stop hook. Is set to "stop" for a container
2445 shutdown or "reboot" for a container reboot.
2446 </para>
2447 </listitem>
2448 </varlistentry>
2449 </variablelist>
2450 <variablelist>
2451 <varlistentry>
2452 <term>
2453 <option>LXC_CGNS_AWARE</option>
2454 </term>
2455 <listitem>
2456 <para>
2457 If unset, then this version of lxc is not aware of cgroup
2458 namespaces. If set, it will be set to 1, and lxc is aware
2459 of cgroup namespaces. Note this does not guarantee that
2460 cgroup namespaces are enabled in the kernel. This is used
2461 by the lxcfs mount hook.
2462 </para>
2463 </listitem>
2464 </varlistentry>
2465 </variablelist>
2466 </refsect2>
2467 <refsect2>
2468 <title>Logging</title>
2469 <para>
2470 Logging can be configured on a per-container basis. By default,
2471 depending upon how the lxc package was compiled, container startup
2472 is logged only at the ERROR level, and logged to a file named after
2473 the container (with '.log' appended) either under the container path,
2474 or under @LOGPATH@.
2475 </para>
2476 <para>
2477 Both the default log level and the log file can be specified in the
2478 container configuration file, overriding the default behavior. Note
2479 that the configuration file entries can in turn be overridden by the
2480 command line options to <command>lxc-start</command>.
2481 </para>
2482 <variablelist>
2483 <varlistentry>
2484 <term>
2485 <option>lxc.log.level</option>
2486 </term>
2487 <listitem>
2488 <para>
2489 The level at which to log. The log level is an integer in
2490 the range of 0..8 inclusive, where a lower number means more
2491 verbose debugging. In particular 0 = trace, 1 = debug, 2 =
2492 info, 3 = notice, 4 = warn, 5 = error, 6 = critical, 7 =
2493 alert, and 8 = fatal. If unspecified, the level defaults
2494 to 5 (error), so that only errors and above are logged.
2495 </para>
2496 <para>
2497 Note that when a script (such as either a hook script or a
2498 network interface up or down script) is called, the script's
2499 standard output is logged at level 1, debug.
2500 </para>
2501 </listitem>
2502 </varlistentry>
2503 <varlistentry>
2504 <term>
2505 <option>lxc.log.file</option>
2506 </term>
2507 <listitem>
2508 <para>
2509 The file to which logging info should be written.
2510 </para>
2511 </listitem>
2512 </varlistentry>
2513 <varlistentry>
2514 <term>
2515 <option>lxc.log.syslog</option>
2516 </term>
2517 <listitem>
2518 <para>
2519 Send logging info to syslog. It respects the log level defined in
2520 <command>lxc.log.level</command>. The argument should be the syslog
2521 facility to use, valid ones are: daemon, local0, local1, local2,
2522 local3, local4, local5, local5, local6, local7.
2523 </para>
2524 </listitem>
2525 </varlistentry>
2526 </variablelist>
2527 </refsect2>
2528
2529 <refsect2>
2530 <title>Autostart</title>
2531 <para>
2532 The autostart options support marking which containers should be
2533 auto-started and in what order. These options may be used by LXC tools
2534 directly or by external tooling provided by the distributions.
2535 </para>
2536
2537 <variablelist>
2538 <varlistentry>
2539 <term>
2540 <option>lxc.start.auto</option>
2541 </term>
2542 <listitem>
2543 <para>
2544 Whether the container should be auto-started.
2545 Valid values are 0 (off) and 1 (on).
2546 </para>
2547 </listitem>
2548 </varlistentry>
2549 <varlistentry>
2550 <term>
2551 <option>lxc.start.delay</option>
2552 </term>
2553 <listitem>
2554 <para>
2555 How long to wait (in seconds) after the container is
2556 started before starting the next one.
2557 </para>
2558 </listitem>
2559 </varlistentry>
2560 <varlistentry>
2561 <term>
2562 <option>lxc.start.order</option>
2563 </term>
2564 <listitem>
2565 <para>
2566 An integer used to sort the containers when auto-starting
2567 a series of containers at once.
2568 </para>
2569 </listitem>
2570 </varlistentry>
2571 <varlistentry>
2572 <term>
2573 <option>lxc.monitor.unshare</option>
2574 </term>
2575 <listitem>
2576 <para>
2577 If not zero the mount namespace will be unshared from the host
2578 before initializing the container (before running any pre-start
2579 hooks). This requires the CAP_SYS_ADMIN capability at startup.
2580 Default is 0.
2581 </para>
2582 </listitem>
2583 </varlistentry>
2584 <varlistentry>
2585 <term>
2586 <option>lxc.monitor.signal.pdeath</option>
2587 </term>
2588 <listitem>
2589 <para>
2590 Set the signal to be sent to the container's init when the lxc
2591 monitor exits. By default it is set to SIGKILL which will cause
2592 all container processes to be killed when the lxc monitor process
2593 dies.
2594 To ensure that containers stay alive even if lxc monitor dies set
2595 this to 0.
2596 </para>
2597 </listitem>
2598 </varlistentry>
2599 <varlistentry>
2600 <term>
2601 <option>lxc.group</option>
2602 </term>
2603 <listitem>
2604 <para>
2605 A multi-value key (can be used multiple times) to put the
2606 container in a container group. Those groups can then be
2607 used (amongst other things) to start a series of related
2608 containers.
2609 </para>
2610 </listitem>
2611 </varlistentry>
2612 </variablelist>
2613 </refsect2>
2614
2615 <refsect2>
2616 <title>Autostart and System Boot</title>
2617 <para>
2618 Each container can be part of any number of groups or no group at all.
2619 Two groups are special. One is the NULL group, i.e. the container does
2620 not belong to any group. The other group is the "onboot" group.
2621 </para>
2622
2623 <para>
2624 When the system boots with the LXC service enabled, it will first
2625 attempt to boot any containers with lxc.start.auto == 1 that is a member
2626 of the "onboot" group. The startup will be in order of lxc.start.order.
2627 If an lxc.start.delay has been specified, that delay will be honored
2628 before attempting to start the next container to give the current
2629 container time to begin initialization and reduce overloading the host
2630 system. After starting the members of the "onboot" group, the LXC system
2631 will proceed to boot containers with lxc.start.auto == 1 which are not
2632 members of any group (the NULL group) and proceed as with the onboot
2633 group.
2634 </para>
2635
2636 </refsect2>
2637
2638 <refsect2>
2639 <title>Container Environment</title>
2640 <para>
2641 If you want to pass environment variables into the container (that
2642 is, environment variables which will be available to init and all of
2643 its descendents), you can use <command>lxc.environment</command>
2644 parameters to do so. Be careful that you do not pass in anything
2645 sensitive; any process in the container which doesn't have its
2646 environment scrubbed will have these variables available to it, and
2647 environment variables are always available via
2648 <command>/proc/PID/environ</command>.
2649 </para>
2650
2651 <para>
2652 This configuration parameter can be specified multiple times; once
2653 for each environment variable you wish to configure.
2654 </para>
2655
2656 <variablelist>
2657 <varlistentry>
2658 <term>
2659 <option>lxc.environment</option>
2660 </term>
2661 <listitem>
2662 <para>
2663 Specify an environment variable to pass into the container.
2664 Example:
2665 </para>
2666 <programlisting>
2667 lxc.environment = APP_ENV=production
2668 lxc.environment = SYSLOG_SERVER=192.0.2.42
2669 </programlisting>
2670 <para>
2671 It is possible to inherit host environment variables by setting the
2672 name of the variable without a "=" sign. For example:
2673 </para>
2674 <programlisting>
2675 lxc.environment = PATH
2676 </programlisting>
2677 </listitem>
2678 </varlistentry>
2679 </variablelist>
2680 </refsect2>
2681
2682 </refsect1>
2683
2684 <refsect1>
2685 <title>Examples</title>
2686 <para>
2687 In addition to the few examples given below, you will find
2688 some other examples of configuration file in @DOCDIR@/examples
2689 </para>
2690 <refsect2>
2691 <title>Network</title>
2692 <para>This configuration sets up a container to use a veth pair
2693 device with one side plugged to a bridge br0 (which has been
2694 configured before on the system by the administrator). The
2695 virtual network device visible in the container is renamed to
2696 eth0.</para>
2697 <programlisting>
2698 lxc.uts.name = myhostname
2699 lxc.net.0.type = veth
2700 lxc.net.0.flags = up
2701 lxc.net.0.link = br0
2702 lxc.net.0.name = eth0
2703 lxc.net.0.hwaddr = 4a:49:43:49:79:bf
2704 lxc.net.0.ipv4.address = 10.2.3.5/24 10.2.3.255
2705 lxc.net.0.ipv6.address = 2003:db8:1:0:214:1234:fe0b:3597
2706 </programlisting>
2707 </refsect2>
2708
2709 <refsect2>
2710 <title>UID/GID mapping</title>
2711 <para>This configuration will map both user and group ids in the
2712 range 0-9999 in the container to the ids 100000-109999 on the host.
2713 </para>
2714 <programlisting>
2715 lxc.idmap = u 0 100000 10000
2716 lxc.idmap = g 0 100000 10000
2717 </programlisting>
2718 </refsect2>
2719
2720 <refsect2>
2721 <title>Control group</title>
2722 <para>This configuration will setup several control groups for
2723 the application, cpuset.cpus restricts usage of the defined cpu,
2724 cpus.share prioritize the control group, devices.allow makes
2725 usable the specified devices.</para>
2726 <programlisting>
2727 lxc.cgroup.cpuset.cpus = 0,1
2728 lxc.cgroup.cpu.shares = 1234
2729 lxc.cgroup.devices.deny = a
2730 lxc.cgroup.devices.allow = c 1:3 rw
2731 lxc.cgroup.devices.allow = b 8:0 rw
2732 </programlisting>
2733 </refsect2>
2734
2735 <refsect2>
2736 <title>Complex configuration</title>
2737 <para>This example show a complex configuration making a complex
2738 network stack, using the control groups, setting a new hostname,
2739 mounting some locations and a changing root file system.</para>
2740 <programlisting>
2741 lxc.uts.name = complex
2742 lxc.net.0.type = veth
2743 lxc.net.0.flags = up
2744 lxc.net.0.link = br0
2745 lxc.net.0.hwaddr = 4a:49:43:49:79:bf
2746 lxc.net.0.ipv4.address = 10.2.3.5/24 10.2.3.255
2747 lxc.net.0.ipv6.address = 2003:db8:1:0:214:1234:fe0b:3597
2748 lxc.net.0.ipv6.address = 2003:db8:1:0:214:5432:feab:3588
2749 lxc.net.1.type = macvlan
2750 lxc.net.1.flags = up
2751 lxc.net.1.link = eth0
2752 lxc.net.1.hwaddr = 4a:49:43:49:79:bd
2753 lxc.net.1.ipv4.address = 10.2.3.4/24
2754 lxc.net.1.ipv4.address = 192.168.10.125/24
2755 lxc.net.1.ipv6.address = 2003:db8:1:0:214:1234:fe0b:3596
2756 lxc.net.2.type = phys
2757 lxc.net.2.flags = up
2758 lxc.net.2.link = dummy0
2759 lxc.net.2.hwaddr = 4a:49:43:49:79:ff
2760 lxc.net.2.ipv4.address = 10.2.3.6/24
2761 lxc.net.2.ipv6.address = 2003:db8:1:0:214:1234:fe0b:3297
2762 lxc.cgroup.cpuset.cpus = 0,1
2763 lxc.cgroup.cpu.shares = 1234
2764 lxc.cgroup.devices.deny = a
2765 lxc.cgroup.devices.allow = c 1:3 rw
2766 lxc.cgroup.devices.allow = b 8:0 rw
2767 lxc.mount.fstab = /etc/fstab.complex
2768 lxc.mount.entry = /lib /root/myrootfs/lib none ro,bind 0 0
2769 lxc.rootfs.path = dir:/mnt/rootfs.complex
2770 lxc.cap.drop = sys_module mknod setuid net_raw
2771 lxc.cap.drop = mac_override
2772 </programlisting>
2773 </refsect2>
2774
2775 </refsect1>
2776
2777 <refsect1>
2778 <title>See Also</title>
2779 <simpara>
2780 <citerefentry>
2781 <refentrytitle><command>chroot</command></refentrytitle>
2782 <manvolnum>1</manvolnum>
2783 </citerefentry>,
2784
2785 <citerefentry>
2786 <refentrytitle><command>pivot_root</command></refentrytitle>
2787 <manvolnum>8</manvolnum>
2788 </citerefentry>,
2789
2790 <citerefentry>
2791 <refentrytitle><filename>fstab</filename></refentrytitle>
2792 <manvolnum>5</manvolnum>
2793 </citerefentry>,
2794
2795 <citerefentry>
2796 <refentrytitle><filename>capabilities</filename></refentrytitle>
2797 <manvolnum>7</manvolnum>
2798 </citerefentry>
2799 </simpara>
2800 </refsect1>
2801
2802 &seealso;
2803
2804 <refsect1>
2805 <title>Author</title>
2806 <para>Daniel Lezcano <email>daniel.lezcano@free.fr</email></para>
2807 </refsect1>
2808
2809 </refentry>
2810
2811 <!-- Keep this comment at the end of the file
2812 Local variables:
2813 mode: sgml
2814 sgml-omittag:t
2815 sgml-shorttag:t
2816 sgml-minimize-attributes:nil
2817 sgml-always-quote-attributes:t
2818 sgml-indent-step:2
2819 sgml-indent-data:t
2820 sgml-parent-document:nil
2821 sgml-default-dtd-file:nil
2822 sgml-exposed-tags:nil
2823 sgml-local-catalogs:nil
2824 sgml-local-ecat-files:nil
2825 End:
2826 -->