]> git.proxmox.com Git - mirror_lxc.git/blob - doc/lxc.container.conf.sgml.in
Merge pull request #3244 from Rachid-Koucha/master
[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 by default, unless defined in lxc.autodev.tmpfs.size)
1068 and fill in a minimal set of initial devices.
1069 This is generally required when starting a container containing
1070 a "systemd" based "init" but may be optional at other times. Additional
1071 devices in the containers /dev directory may be created through the
1072 use of the <option>lxc.hook.autodev</option> hook.
1073 </para>
1074 <variablelist>
1075 <varlistentry>
1076 <term>
1077 <option>lxc.autodev</option>
1078 </term>
1079 <listitem>
1080 <para>
1081 Set this to 0 to stop LXC from mounting and populating a minimal
1082 <filename>/dev</filename> when starting the container.
1083 </para>
1084 </listitem>
1085 </varlistentry>
1086
1087 <varlistentry>
1088 <term>
1089 <option>lxc.autodev.tmpfs.size</option>
1090 </term>
1091 <listitem>
1092 <para>
1093 Set this to define the size of the /dev tmpfs.
1094 The default value is 500000 (500K). If the parameter is used
1095 but without value, the default value is used.
1096 </para>
1097 </listitem>
1098 </varlistentry>
1099 </variablelist>
1100 </refsect2>
1101
1102 <refsect2>
1103 <title>Mount points</title>
1104 <para>
1105 The mount points section specifies the different places to be
1106 mounted. These mount points will be private to the container
1107 and won't be visible by the processes running outside of the
1108 container. This is useful to mount /etc, /var or /home for
1109 examples.
1110 </para>
1111 <para>
1112 NOTE - LXC will generally ensure that mount targets and relative
1113 bind-mount sources are properly confined under the container
1114 root, to avoid attacks involving over-mounting host directories
1115 and files. (Symbolic links in absolute mount sources are ignored)
1116 However, if the container configuration first mounts a directory which
1117 is under the control of the container user, such as /home/joe, into
1118 the container at some <filename>path</filename>, and then mounts
1119 under <filename>path</filename>, then a TOCTTOU attack would be
1120 possible where the container user modifies a symbolic link under
1121 his home directory at just the right time.
1122 </para>
1123 <variablelist>
1124 <varlistentry>
1125 <term>
1126 <option>lxc.mount.fstab</option>
1127 </term>
1128 <listitem>
1129 <para>
1130 specify a file location in
1131 the <filename>fstab</filename> format, containing the
1132 mount information. The mount target location can and in
1133 most cases should be a relative path, which will become
1134 relative to the mounted container root. For instance,
1135 </para>
1136 <programlisting>
1137 proc proc proc nodev,noexec,nosuid 0 0
1138 </programlisting>
1139 <para>
1140 Will mount a proc filesystem under the container's /proc,
1141 regardless of where the root filesystem comes from. This
1142 is resilient to block device backed filesystems as well as
1143 container cloning.
1144 </para>
1145 <para>
1146 Note that when mounting a filesystem from an
1147 image file or block device the third field (fs_vfstype)
1148 cannot be auto as with
1149 <citerefentry>
1150 <refentrytitle>mount</refentrytitle>
1151 <manvolnum>8</manvolnum>
1152 </citerefentry>
1153 but must be explicitly specified.
1154 </para>
1155 </listitem>
1156 </varlistentry>
1157
1158 <varlistentry>
1159 <term>
1160 <option>lxc.mount.entry</option>
1161 </term>
1162 <listitem>
1163 <para>
1164 Specify a mount point corresponding to a line in the
1165 fstab format.
1166
1167 Moreover lxc supports mount propagation, such as rslave or
1168 rprivate, and adds three additional mount options.
1169 <option>optional</option> don't fail if mount does not work.
1170 <option>create=dir</option> or <option>create=file</option>
1171 to create dir (or file) when the point will be mounted.
1172 <option>relative</option> source path is taken to be relative to
1173 the mounted container root. For instance,
1174 </para>
1175 <programlisting>
1176 dev/null proc/kcore none bind,relative 0 0
1177 </programlisting>
1178 <para>
1179 Will expand dev/null to ${<option>LXC_ROOTFS_MOUNT</option>}/dev/null,
1180 and mount it to proc/kcore inside the container.
1181 </para>
1182 </listitem>
1183 </varlistentry>
1184
1185 <varlistentry>
1186 <term>
1187 <option>lxc.mount.auto</option>
1188 </term>
1189 <listitem>
1190 <para>
1191 specify which standard kernel file systems should be
1192 automatically mounted. This may dramatically simplify
1193 the configuration. The file systems are:
1194 </para>
1195 <itemizedlist>
1196 <listitem>
1197 <para>
1198 <option>proc:mixed</option> (or <option>proc</option>):
1199 mount <filename>/proc</filename> as read-write, but
1200 remount <filename>/proc/sys</filename> and
1201 <filename>/proc/sysrq-trigger</filename> read-only
1202 for security / container isolation purposes.
1203 </para>
1204 </listitem>
1205 <listitem>
1206 <para>
1207 <option>proc:rw</option>: mount
1208 <filename>/proc</filename> as read-write
1209 </para>
1210 </listitem>
1211 <listitem>
1212 <para>
1213 <option>sys:mixed</option> (or <option>sys</option>):
1214 mount <filename>/sys</filename> as read-only but with
1215 /sys/devices/virtual/net writable.
1216 </para>
1217 </listitem>
1218 <listitem>
1219 <para>
1220 <option>sys:ro</option>:
1221 mount <filename>/sys</filename> as read-only
1222 for security / container isolation purposes.
1223 </para>
1224 </listitem>
1225 <listitem>
1226 <para>
1227 <option>sys:rw</option>: mount
1228 <filename>/sys</filename> as read-write
1229 </para>
1230 </listitem>
1231
1232 <listitem>
1233 <para>
1234 <option>cgroup:mixed</option>:
1235 Mount a tmpfs to <filename>/sys/fs/cgroup</filename>,
1236 create directories for all hierarchies to which the container
1237 is added, create subdirectories in those hierarchies with the
1238 name of the cgroup, and bind-mount the container's own cgroup
1239 into that directory. The container will be able to write to
1240 its own cgroup directory, but not the parents, since they will
1241 be remounted read-only.
1242 </para>
1243 </listitem>
1244
1245 <listitem>
1246 <para>
1247 <option>cgroup:mixed:force</option>:
1248 The <option>force</option> option will cause LXC to perform
1249 the cgroup mounts for the container under all circumstances.
1250 Otherwise it is similar to <option>cgroup:mixed</option>.
1251 This is mainly useful when the cgroup namespaces are enabled
1252 where LXC will normally leave mounting cgroups to the init
1253 binary of the container since it is perfectly safe to do so.
1254 </para>
1255 </listitem>
1256
1257 <listitem>
1258 <para>
1259 <option>cgroup:ro</option>:
1260 similar to <option>cgroup:mixed</option>, but everything will
1261 be mounted read-only.
1262 </para>
1263 </listitem>
1264
1265 <listitem>
1266 <para>
1267 <option>cgroup:ro:force</option>:
1268 The <option>force</option> option will cause LXC to perform
1269 the cgroup mounts for the container under all circumstances.
1270 Otherwise it is similar to <option>cgroup:ro</option>.
1271 This is mainly useful when the cgroup namespaces are enabled
1272 where LXC will normally leave mounting cgroups to the init
1273 binary of the container since it is perfectly safe to do so.
1274 </para>
1275 </listitem>
1276
1277 <listitem>
1278 <para>
1279 <option>cgroup:rw</option>: similar to
1280 <option>cgroup:mixed</option>, but everything will be mounted
1281 read-write. Note that the paths leading up to the container's
1282 own cgroup will be writable, but will not be a cgroup
1283 filesystem but just part of the tmpfs of
1284 <filename>/sys/fs/cgroup</filename>
1285 </para>
1286 </listitem>
1287
1288 <listitem>
1289 <para>
1290 <option>cgroup:rw:force</option>:
1291 The <option>force</option> option will cause LXC to perform
1292 the cgroup mounts for the container under all circumstances.
1293 Otherwise it is similar to <option>cgroup:rw</option>.
1294 This is mainly useful when the cgroup namespaces are enabled
1295 where LXC will normally leave mounting cgroups to the init
1296 binary of the container since it is perfectly safe to do so.
1297 </para>
1298 </listitem>
1299
1300 <listitem>
1301 <para>
1302 <option>cgroup</option> (without specifier):
1303 defaults to <option>cgroup:rw</option> if the
1304 container retains the CAP_SYS_ADMIN capability,
1305 <option>cgroup:mixed</option> otherwise.
1306 </para>
1307 </listitem>
1308
1309 <listitem>
1310 <para>
1311 <option>cgroup-full:mixed</option>:
1312 mount a tmpfs to <filename>/sys/fs/cgroup</filename>,
1313 create directories for all hierarchies to which
1314 the container is added, bind-mount the hierarchies
1315 from the host to the container and make everything
1316 read-only except the container's own cgroup. Note
1317 that compared to <option>cgroup</option>, where
1318 all paths leading up to the container's own cgroup
1319 are just simple directories in the underlying
1320 tmpfs, here
1321 <filename>/sys/fs/cgroup/$hierarchy</filename>
1322 will contain the host's full cgroup hierarchy,
1323 albeit read-only outside the container's own cgroup.
1324 This may leak quite a bit of information into the
1325 container.
1326 </para>
1327 </listitem>
1328
1329 <listitem>
1330 <para>
1331 <option>cgroup-full:mixed:force</option>:
1332 The <option>force</option> option will cause LXC to perform
1333 the cgroup mounts for the container under all circumstances.
1334 Otherwise it is similar to <option>cgroup-full:mixed</option>.
1335 This is mainly useful when the cgroup namespaces are enabled
1336 where LXC will normally leave mounting cgroups to the init
1337 binary of the container since it is perfectly safe to do so.
1338 </para>
1339 </listitem>
1340
1341 <listitem>
1342 <para>
1343 <option>cgroup-full:ro</option>: similar to
1344 <option>cgroup-full:mixed</option>, but everything
1345 will be mounted read-only.
1346 </para>
1347 </listitem>
1348
1349 <listitem>
1350 <para>
1351 <option>cgroup-full:ro:force</option>:
1352 The <option>force</option> option will cause LXC to perform
1353 the cgroup mounts for the container under all circumstances.
1354 Otherwise it is similar to <option>cgroup-full:ro</option>.
1355 This is mainly useful when the cgroup namespaces are enabled
1356 where LXC will normally leave mounting cgroups to the init
1357 binary of the container since it is perfectly safe to do so.
1358 </para>
1359 </listitem>
1360
1361 <listitem>
1362 <para>
1363 <option>cgroup-full:rw</option>: similar to
1364 <option>cgroup-full:mixed</option>, but everything
1365 will be mounted read-write. Note that in this case,
1366 the container may escape its own cgroup. (Note also
1367 that if the container has CAP_SYS_ADMIN support
1368 and can mount the cgroup filesystem itself, it may
1369 do so anyway.)
1370 </para>
1371 </listitem>
1372
1373 <listitem>
1374 <para>
1375 <option>cgroup-full:rw:force</option>:
1376 The <option>force</option> option will cause LXC to perform
1377 the cgroup mounts for the container under all circumstances.
1378 Otherwise it is similar to <option>cgroup-full:rw</option>.
1379 This is mainly useful when the cgroup namespaces are enabled
1380 where LXC will normally leave mounting cgroups to the init
1381 binary of the container since it is perfectly safe to do so.
1382 </para>
1383 </listitem>
1384
1385 <listitem>
1386 <para>
1387 <option>cgroup-full</option> (without specifier):
1388 defaults to <option>cgroup-full:rw</option> if the
1389 container retains the CAP_SYS_ADMIN capability,
1390 <option>cgroup-full:mixed</option> otherwise.
1391 </para>
1392 </listitem>
1393
1394 </itemizedlist>
1395 <para>
1396 If cgroup namespaces are enabled, then any <option>cgroup</option>
1397 auto-mounting request will be ignored, since the container can
1398 mount the filesystems itself, and automounting can confuse the
1399 container init.
1400 </para>
1401 <para>
1402 Note that if automatic mounting of the cgroup filesystem
1403 is enabled, the tmpfs under
1404 <filename>/sys/fs/cgroup</filename> will always be
1405 mounted read-write (but for the <option>:mixed</option>
1406 and <option>:ro</option> cases, the individual
1407 hierarchies,
1408 <filename>/sys/fs/cgroup/$hierarchy</filename>, will be
1409 read-only). This is in order to work around a quirk in
1410 Ubuntu's
1411 <citerefentry>
1412 <refentrytitle>mountall</refentrytitle>
1413 <manvolnum>8</manvolnum>
1414 </citerefentry>
1415 command that will cause containers to wait for user
1416 input at boot if
1417 <filename>/sys/fs/cgroup</filename> is mounted read-only
1418 and the container can't remount it read-write due to a
1419 lack of CAP_SYS_ADMIN.
1420 </para>
1421 <para>
1422 Examples:
1423 </para>
1424 <programlisting>
1425 lxc.mount.auto = proc sys cgroup
1426 lxc.mount.auto = proc:rw sys:rw cgroup-full:rw
1427 </programlisting>
1428 </listitem>
1429 </varlistentry>
1430
1431 </variablelist>
1432 </refsect2>
1433
1434 <refsect2>
1435 <title>Root file system</title>
1436 <para>
1437 The root file system of the container can be different than that
1438 of the host system.
1439 </para>
1440 <variablelist>
1441 <varlistentry>
1442 <term>
1443 <option>lxc.rootfs.path</option>
1444 </term>
1445 <listitem>
1446 <para>
1447 specify the root file system for the container. It can
1448 be an image file, a directory or a block device. If not
1449 specified, the container shares its root file system
1450 with the host.
1451 </para>
1452 <para>
1453 For directory or simple block-device backed containers,
1454 a pathname can be used. If the rootfs is backed by a nbd
1455 device, then <filename>nbd:file:1</filename> specifies that
1456 <filename>file</filename> should be attached to a nbd device,
1457 and partition 1 should be mounted as the rootfs.
1458 <filename>nbd:file</filename> specifies that the nbd device
1459 itself should be mounted. <filename>overlayfs:/lower:/upper</filename>
1460 specifies that the rootfs should be an overlay with <filename>/upper</filename>
1461 being mounted read-write over a read-only mount of <filename>/lower</filename>.
1462 For <filename>overlay</filename> multiple <filename>/lower</filename>
1463 directories can be specified. <filename>loop:/file</filename> tells lxc to attach
1464 <filename>/file</filename> to a loop device and mount the loop device.
1465 </para>
1466 </listitem>
1467 </varlistentry>
1468
1469 <varlistentry>
1470 <term>
1471 <option>lxc.rootfs.mount</option>
1472 </term>
1473 <listitem>
1474 <para>
1475 where to recursively bind <option>lxc.rootfs.path</option>
1476 before pivoting. This is to ensure success of the
1477 <citerefentry>
1478 <refentrytitle><command>pivot_root</command></refentrytitle>
1479 <manvolnum>8</manvolnum>
1480 </citerefentry>
1481 syscall. Any directory suffices, the default should
1482 generally work.
1483 </para>
1484 </listitem>
1485 </varlistentry>
1486
1487 <varlistentry>
1488 <term>
1489 <option>lxc.rootfs.options</option>
1490 </term>
1491 <listitem>
1492 <para>
1493 extra mount options to use when mounting the rootfs.
1494 </para>
1495 </listitem>
1496 </varlistentry>
1497
1498 <varlistentry>
1499 <term>
1500 <option>lxc.rootfs.managed</option>
1501 </term>
1502 <listitem>
1503 <para>
1504 Set this to 0 to indicate that LXC is not managing the
1505 container storage, then LXC will not modify the
1506 container storage. The default is 1.
1507 </para>
1508 </listitem>
1509 </varlistentry>
1510
1511 </variablelist>
1512 </refsect2>
1513
1514 <refsect2>
1515 <title>Control group</title>
1516 <para>
1517 The control group section contains the configuration for the
1518 different subsystem. <command>lxc</command> does not check the
1519 correctness of the subsystem name. This has the disadvantage
1520 of not detecting configuration errors until the container is
1521 started, but has the advantage of permitting any future
1522 subsystem.
1523 </para>
1524 <variablelist>
1525 <varlistentry>
1526 <term>
1527 <option>lxc.cgroup.[controller name]</option>
1528 </term>
1529 <listitem>
1530 <para>
1531 Specify the control group value to be set on a legacy cgroup
1532 hierarchy. The controller name is the literal name of the control
1533 group. The permitted names and the syntax of their values is not
1534 dictated by LXC, instead it depends on the features of the Linux
1535 kernel running at the time the container is started, eg.
1536 <option>lxc.cgroup.cpuset.cpus</option>
1537 </para>
1538 </listitem>
1539 </varlistentry>
1540 <varlistentry>
1541 <term>
1542 <option>lxc.cgroup2.[controller name]</option>
1543 </term>
1544 <listitem>
1545 <para>
1546 Specify the control group value to be set on the unified cgroup
1547 hierarchy. The controller name is the literal name of the control
1548 group. The permitted names and the syntax of their values is not
1549 dictated by LXC, instead it depends on the features of the Linux
1550 kernel running at the time the container is started, eg.
1551 <option>lxc.cgroup2.memory.high</option>
1552 </para>
1553 </listitem>
1554 </varlistentry>
1555 <varlistentry>
1556 <term>
1557 <option>lxc.cgroup.dir</option>
1558 </term>
1559 <listitem>
1560 <para>
1561 specify a directory or path in which the container's cgroup will
1562 be created. For example, setting
1563 <option>lxc.cgroup.dir = my-cgroup/first</option> for a container
1564 named "c1" will create the container's cgroup as a sub-cgroup of
1565 "my-cgroup". For example, if the user's current cgroup "my-user"
1566 is located in the root cgroup of the cpuset controller in a
1567 cgroup v1 hierarchy this would create the cgroup
1568 "/sys/fs/cgroup/cpuset/my-user/my-cgroup/first/c1" for the
1569 container. Any missing cgroups will be created by LXC. This
1570 presupposes that the user has write access to its current cgroup.
1571 </para>
1572 </listitem>
1573 </varlistentry>
1574 <varlistentry>
1575 <term>
1576 <option>lxc.cgroup.relative</option>
1577 </term>
1578 <listitem>
1579 <para>
1580 Set this to 1 to instruct LXC to never escape to the
1581 root cgroup. This makes it easy for users to adhere to
1582 restrictions enforced by cgroup2 and
1583 systemd. Specifically, this makes it possible to run LXC
1584 containers as systemd services.
1585 </para>
1586 </listitem>
1587 </varlistentry>
1588 </variablelist>
1589 </refsect2>
1590
1591 <refsect2>
1592 <title>Capabilities</title>
1593 <para>
1594 The capabilities can be dropped in the container if this one
1595 is run as root.
1596 </para>
1597 <variablelist>
1598 <varlistentry>
1599 <term>
1600 <option>lxc.cap.drop</option>
1601 </term>
1602 <listitem>
1603 <para>
1604 Specify the capability to be dropped in the container. A
1605 single line defining several capabilities with a space
1606 separation is allowed. The format is the lower case of
1607 the capability definition without the "CAP_" prefix,
1608 eg. CAP_SYS_MODULE should be specified as
1609 sys_module. See
1610 <citerefentry>
1611 <refentrytitle><command>capabilities</command></refentrytitle>
1612 <manvolnum>7</manvolnum>
1613 </citerefentry>.
1614 If used with no value, lxc will clear any drop capabilities
1615 specified up to this point.
1616 </para>
1617 </listitem>
1618 </varlistentry>
1619 <varlistentry>
1620 <term>
1621 <option>lxc.cap.keep</option>
1622 </term>
1623 <listitem>
1624 <para>
1625 Specify the capability to be kept in the container. All other
1626 capabilities will be dropped. When a special value of "none" is
1627 encountered, lxc will clear any keep capabilities specified up
1628 to this point. A value of "none" alone can be used to drop all
1629 capabilities.
1630 </para>
1631 </listitem>
1632 </varlistentry>
1633 </variablelist>
1634 </refsect2>
1635
1636 <refsect2>
1637 <title>Namespaces</title>
1638 <para>
1639 A namespace can be cloned (<option>lxc.namespace.clone</option>),
1640 kept (<option>lxc.namespace.keep</option>) or shared
1641 (<option>lxc.namespace.share.[namespace identifier]</option>).
1642 </para>
1643 <variablelist>
1644 <varlistentry>
1645 <term>
1646 <option>lxc.namespace.clone</option>
1647 </term>
1648 <listitem>
1649 <para>
1650 Specify namespaces which the container is supposed to be created
1651 with. The namespaces to create are specified as a space separated
1652 list. Each namespace must correspond to one of the standard
1653 namespace identifiers as seen in the
1654 <filename>/proc/PID/ns</filename> directory.
1655 When <option>lxc.namespace.clone</option> is not explicitly set all
1656 namespaces supported by the kernel and the current configuration
1657 will be used.
1658 </para>
1659
1660 <para>
1661 To create a new mount, net and ipc namespace set
1662 <option>lxc.namespace.clone=mount net ipc</option>.
1663 </para>
1664 </listitem>
1665 </varlistentry>
1666
1667 <varlistentry>
1668 <term>
1669 <option>lxc.namespace.keep</option>
1670 </term>
1671 <listitem>
1672 <para>
1673 Specify namespaces which the container is supposed to inherit from
1674 the process that created it. The namespaces to keep are specified as
1675 a space separated list. Each namespace must correspond to one of the
1676 standard namespace identifiers as seen in the
1677 <filename>/proc/PID/ns</filename> directory.
1678 The <option>lxc.namespace.keep</option> is a
1679 blacklist option, i.e. it is useful when enforcing that containers
1680 must keep a specific set of namespaces.
1681 </para>
1682
1683 <para>
1684 To keep the network, user and ipc namespace set
1685 <option>lxc.namespace.keep=user net ipc</option>.
1686 </para>
1687
1688 <para>
1689 Note that sharing pid namespaces will likely not work with most init
1690 systems.
1691 </para>
1692
1693 <para>
1694 Note that if the container requests a new user namespace and the
1695 container wants to inherit the network namespace it needs to inherit
1696 the user namespace as well.
1697 </para>
1698 </listitem>
1699 </varlistentry>
1700
1701 <varlistentry>
1702 <term>
1703 <option>lxc.namespace.share.[namespace identifier]</option>
1704 </term>
1705 <listitem>
1706 <para>
1707 Specify a namespace to inherit from another container or process.
1708 The <option>[namespace identifier]</option> suffix needs to be
1709 replaced with one of the namespaces that appear in the
1710 <filename>/proc/PID/ns</filename> directory.
1711 </para>
1712
1713 <para>
1714 To inherit the namespace from another process set the
1715 <option>lxc.namespace.share.[namespace identifier]</option> to the PID of
1716 the process, e.g. <option>lxc.namespace.share.net=42</option>.
1717 </para>
1718
1719 <para>
1720 To inherit the namespace from another container set the
1721 <option>lxc.namespace.share.[namespace identifier]</option> to the name of
1722 the container, e.g. <option>lxc.namespace.share.pid=c3</option>.
1723 </para>
1724
1725 <para>
1726 To inherit the namespace from another container located in a
1727 different path than the standard liblxc path set the
1728 <option>lxc.namespace.share.[namespace identifier]</option> to the full
1729 path to the container, e.g.
1730 <option>lxc.namespace.share.user=/opt/c3</option>.
1731 </para>
1732
1733 <para>
1734 In order to inherit namespaces the caller needs to have sufficient
1735 privilege over the process or container.
1736 </para>
1737
1738 <para>
1739 Note that sharing pid namespaces between system containers will
1740 likely not work with most init systems.
1741 </para>
1742
1743 <para>
1744 Note that if two processes are in different user namespaces and one
1745 process wants to inherit the other's network namespace it usually
1746 needs to inherit the user namespace as well.
1747 </para>
1748
1749 <para>
1750 Note that without careful additional configuration of an LSM,
1751 sharing user+pid namespaces with a task may allow that task to
1752 escalate privileges to that of the task calling liblxc.
1753 </para>
1754 </listitem>
1755 </varlistentry>
1756 </variablelist>
1757 </refsect2>
1758
1759 <refsect2>
1760 <title>Resource limits</title>
1761 <para>
1762 The soft and hard resource limits for the container can be changed.
1763 Unprivileged containers can only lower them. Resources which are not
1764 explicitly specified will be inherited.
1765 </para>
1766 <variablelist>
1767 <varlistentry>
1768 <term>
1769 <option>lxc.prlimit.[limit name]</option>
1770 </term>
1771 <listitem>
1772 <para>
1773 Specify the resource limit to be set. A limit is specified as two
1774 colon separated values which are either numeric or the word
1775 'unlimited'. A single value can be used as a shortcut to set both
1776 soft and hard limit to the same value. The permitted names the
1777 "RLIMIT_" resource names in lowercase without the "RLIMIT_"
1778 prefix, eg. RLIMIT_NOFILE should be specified as "nofile". See
1779 <citerefentry>
1780 <refentrytitle><command>setrlimit</command></refentrytitle>
1781 <manvolnum>2</manvolnum>
1782 </citerefentry>.
1783 If used with no value, lxc will clear the resource limit
1784 specified up to this point. A resource with no explicitly
1785 configured limitation will be inherited from the process starting
1786 up the container.
1787 </para>
1788 </listitem>
1789 </varlistentry>
1790 </variablelist>
1791 </refsect2>
1792
1793 <refsect2>
1794 <title>Sysctl</title>
1795 <para>
1796 Configure kernel parameters for the container.
1797 </para>
1798 <variablelist>
1799 <varlistentry>
1800 <term>
1801 <option>lxc.sysctl.[kernel parameters name]</option>
1802 </term>
1803 <listitem>
1804 <para>
1805 Specify the kernel parameters to be set. The parameters available
1806 are those listed under /proc/sys/.
1807 Note that not all sysctls are namespaced. Changing Non-namespaced
1808 sysctls will cause the system-wide setting to be modified.
1809 <citerefentry>
1810 <refentrytitle><command>sysctl</command></refentrytitle>
1811 <manvolnum>8</manvolnum>
1812 </citerefentry>.
1813 If used with no value, lxc will clear the parameters specified up
1814 to this point.
1815 </para>
1816 </listitem>
1817 </varlistentry>
1818 </variablelist>
1819 </refsect2>
1820
1821 <refsect2>
1822 <title>Apparmor profile</title>
1823 <para>
1824 If lxc was compiled and installed with apparmor support, and the host
1825 system has apparmor enabled, then the apparmor profile under which the
1826 container should be run can be specified in the container
1827 configuration. The default is <command>lxc-container-default-cgns</command>
1828 if the host kernel is cgroup namespace aware, or
1829 <command>lxc-container-default</command> otherwise.
1830 </para>
1831 <variablelist>
1832 <varlistentry>
1833 <term>
1834 <option>lxc.apparmor.profile</option>
1835 </term>
1836 <listitem>
1837 <para>
1838 Specify the apparmor profile under which the container should
1839 be run. To specify that the container should be unconfined,
1840 use
1841 </para>
1842 <programlisting>lxc.apparmor.profile = unconfined</programlisting>
1843 <para>
1844 If the apparmor profile should remain unchanged (i.e. if you
1845 are nesting containers and are already confined), then use
1846 </para>
1847 <programlisting>lxc.apparmor.profile = unchanged</programlisting>
1848 <para>
1849 If you instruct LXC to generate the apparmor profile,
1850 then use
1851 </para>
1852 <programlisting>lxc.apparmor.profile = generated</programlisting>
1853 </listitem>
1854 </varlistentry>
1855 <varlistentry>
1856 <term>
1857 <option>lxc.apparmor.allow_incomplete</option>
1858 </term>
1859 <listitem>
1860 <para>
1861 Apparmor profiles are pathname based. Therefore many file
1862 restrictions require mount restrictions to be effective against
1863 a determined attacker. However, these mount restrictions are not
1864 yet implemented in the upstream kernel. Without the mount
1865 restrictions, the apparmor profiles still protect against accidental
1866 damager.
1867 </para>
1868 <para>
1869 If this flag is 0 (default), then the container will not be
1870 started if the kernel lacks the apparmor mount features, so that a
1871 regression after a kernel upgrade will be detected. To start the
1872 container under partial apparmor protection, set this flag to 1.
1873 </para>
1874 </listitem>
1875 </varlistentry>
1876
1877 <varlistentry>
1878 <term>
1879 <option>lxc.apparmor.allow_nesting</option>
1880 </term>
1881 <listitem>
1882 <para>
1883 If set this to 1, causes the following changes. When
1884 generated apparmor profiles are used, they will contain
1885 the necessary changes to allow creating a nested
1886 container. In addition to the usual mount points,
1887 <filename>/dev/.lxc/proc</filename>
1888 and <filename>/dev/.lxc/sys</filename> will contain
1889 procfs and sysfs mount points without the lxcfs
1890 overlays, which, if generated apparmor profiles are
1891 being used, will not be read/writable directly.
1892 </para>
1893 </listitem>
1894 </varlistentry>
1895
1896 <varlistentry>
1897 <term>
1898 <option>lxc.apparmor.raw</option>
1899 </term>
1900 <listitem>
1901 <para>
1902 A list of raw AppArmor profile lines to append to the
1903 profile. Only valid when using generated profiles.
1904 </para>
1905 </listitem>
1906 </varlistentry>
1907
1908 </variablelist>
1909 </refsect2>
1910
1911 <refsect2>
1912 <title>SELinux context</title>
1913 <para>
1914 If lxc was compiled and installed with SELinux support, and the host
1915 system has SELinux enabled, then the SELinux context under which the
1916 container should be run can be specified in the container
1917 configuration. The default is <command>unconfined_t</command>,
1918 which means that lxc will not attempt to change contexts.
1919 See @DATADIR@/lxc/selinux/lxc.te for an example policy and more
1920 information.
1921 </para>
1922 <variablelist>
1923 <varlistentry>
1924 <term>
1925 <option>lxc.selinux.context</option>
1926 </term>
1927 <listitem>
1928 <para>
1929 Specify the SELinux context under which the container should
1930 be run or <command>unconfined_t</command>. For example
1931 </para>
1932 <programlisting>lxc.selinux.context = system_u:system_r:lxc_t:s0:c22</programlisting>
1933 </listitem>
1934 </varlistentry>
1935 </variablelist>
1936 </refsect2>
1937
1938 <refsect2>
1939 <title>Seccomp configuration</title>
1940 <para>
1941 A container can be started with a reduced set of available
1942 system calls by loading a seccomp profile at startup. The
1943 seccomp configuration file must begin with a version number
1944 on the first line, a policy type on the second line, followed
1945 by the configuration.
1946 </para>
1947 <para>
1948 Versions 1 and 2 are currently supported. In version 1, the
1949 policy is a simple whitelist. The second line therefore must
1950 read "whitelist", with the rest of the file containing one (numeric)
1951 syscall number per line. Each syscall number is whitelisted,
1952 while every unlisted number is blacklisted for use in the container
1953 </para>
1954
1955 <para>
1956 In version 2, the policy may be blacklist or whitelist,
1957 supports per-rule and per-policy default actions, and supports
1958 per-architecture system call resolution from textual names.
1959 </para>
1960 <para>
1961 An example blacklist policy, in which all system calls are
1962 allowed except for mknod, which will simply do nothing and
1963 return 0 (success), looks like:
1964 </para>
1965
1966 <programlisting>
1967 2
1968 blacklist
1969 mknod errno 0
1970 ioctl notify
1971 </programlisting>
1972
1973 <para>
1974 Specifying "errno" as action will cause LXC to register a seccomp filter
1975 that will cause a specific errno to be returned to the caller. The errno
1976 value can be specified after the "errno" action word.
1977 </para>
1978
1979 <para>
1980 Specifying "notify" as action will cause LXC to register a seccomp
1981 listener and retrieve a listener file descriptor from the kernel. When a
1982 syscall is made that is registered as "notify" the kernel will generate a
1983 poll event and send a message over the file descriptor. The caller can
1984 read this message, inspect the syscalls including its arguments. Based on
1985 this information the caller is expected to send back a message informing
1986 the kernel which action to take. Until that message is sent the kernel
1987 will block the calling process. The format of the messages to read and
1988 sent is documented in seccomp itself.
1989 </para>
1990
1991 <variablelist>
1992 <varlistentry>
1993 <term>
1994 <option>lxc.seccomp.profile</option>
1995 </term>
1996 <listitem>
1997 <para>
1998 Specify a file containing the seccomp configuration to
1999 load before the container starts.
2000 </para>
2001 </listitem>
2002 </varlistentry>
2003 <varlistentry>
2004 <term>
2005 <option>lxc.seccomp.allow_nesting</option>
2006 </term>
2007 <listitem>
2008 <para>
2009 If this flag is set to 1, then seccomp filters will be stacked
2010 regardless of whether a seccomp profile is already loaded.
2011 This allows nested containers to load their own seccomp profile.
2012 The default setting is 0.
2013 </para>
2014 </listitem>
2015 </varlistentry>
2016 <varlistentry>
2017 <term>
2018 <option>lxc.seccomp.notify.proxy</option>
2019 </term>
2020 <listitem>
2021 <para>
2022 Specify a unix socket to which LXC will connect and forward
2023 seccomp events to. The path must be in the form
2024 unix:/path/to/socket or unix:@socket. The former specifies a
2025 path-bound unix domain socket while the latter specifies an
2026 abstract unix domain socket.
2027 </para>
2028 </listitem>
2029 </varlistentry>
2030 <varlistentry>
2031 <term>
2032 <option>lxc.seccomp.notify.cookie</option>
2033 </term>
2034 <listitem>
2035 <para>
2036 An additional string sent along with proxied seccomp notification
2037 requests.
2038 </para>
2039 </listitem>
2040 </varlistentry>
2041 </variablelist>
2042 </refsect2>
2043
2044 <refsect2>
2045 <title>PR_SET_NO_NEW_PRIVS</title>
2046 <para>
2047 With PR_SET_NO_NEW_PRIVS active execve() promises not to grant
2048 privileges to do anything that could not have been done without
2049 the execve() call (for example, rendering the set-user-ID and
2050 set-group-ID mode bits, and file capabilities non-functional).
2051 Once set, this bit cannot be unset. The setting of this bit is
2052 inherited by children created by fork() and clone(), and preserved
2053 across execve().
2054 Note that PR_SET_NO_NEW_PRIVS is applied after the container has
2055 changed into its intended AppArmor profile or SElinux context.
2056 </para>
2057 <variablelist>
2058 <varlistentry>
2059 <term>
2060 <option>lxc.no_new_privs</option>
2061 </term>
2062 <listitem>
2063 <para>
2064 Specify whether the PR_SET_NO_NEW_PRIVS flag should be set for the
2065 container. Set to 1 to activate.
2066 </para>
2067 </listitem>
2068 </varlistentry>
2069 </variablelist>
2070 </refsect2>
2071
2072 <refsect2>
2073 <title>UID mappings</title>
2074 <para>
2075 A container can be started in a private user namespace with
2076 user and group id mappings. For instance, you can map userid
2077 0 in the container to userid 200000 on the host. The root
2078 user in the container will be privileged in the container,
2079 but unprivileged on the host. Normally a system container
2080 will want a range of ids, so you would map, for instance,
2081 user and group ids 0 through 20,000 in the container to the
2082 ids 200,000 through 220,000.
2083 </para>
2084 <variablelist>
2085 <varlistentry>
2086 <term>
2087 <option>lxc.idmap</option>
2088 </term>
2089 <listitem>
2090 <para>
2091 Four values must be provided. First a character, either
2092 'u', or 'g', to specify whether user or group ids are
2093 being mapped. Next is the first userid as seen in the
2094 user namespace of the container. Next is the userid as
2095 seen on the host. Finally, a range indicating the number
2096 of consecutive ids to map.
2097 </para>
2098 </listitem>
2099 </varlistentry>
2100 </variablelist>
2101 </refsect2>
2102
2103 <refsect2>
2104 <title>Container hooks</title>
2105 <para>
2106 Container hooks are programs or scripts which can be executed
2107 at various times in a container's lifetime.
2108 </para>
2109 <para>
2110 When a container hook is executed, additional information is passed
2111 along. The <option>lxc.hook.version</option> argument can be used to
2112 determine if the following arguments are passed as command line
2113 arguments or through environment variables. The arguments are:
2114 <itemizedlist>
2115 <listitem><para> Container name. </para></listitem>
2116 <listitem><para> Section (always 'lxc'). </para></listitem>
2117 <listitem><para> The hook type (i.e. 'clone' or 'pre-mount'). </para></listitem>
2118 <listitem><para> Additional arguments. In the
2119 case of the clone hook, any extra arguments passed will appear as
2120 further arguments to the hook. In the case of the stop hook, paths to
2121 filedescriptors for each of the container's namespaces along with
2122 their types are passed. </para></listitem>
2123 </itemizedlist>
2124 The following environment variables are set:
2125 <itemizedlist>
2126 <listitem><para> LXC_CGNS_AWARE: indicator whether the container is
2127 cgroup namespace aware. </para></listitem>
2128 <listitem><para> LXC_CONFIG_FILE: the path to the container
2129 configuration file. </para></listitem>
2130 <listitem><para> LXC_HOOK_TYPE: the hook type (e.g. 'clone', 'mount',
2131 'pre-mount'). Note that the existence of this environment variable is
2132 conditional on the value of <option>lxc.hook.version</option>. If it
2133 is set to 1 then LXC_HOOK_TYPE will be set.
2134 </para></listitem>
2135 <listitem><para> LXC_HOOK_SECTION: the section type (e.g. 'lxc',
2136 'net'). Note that the existence of this environment variable is
2137 conditional on the value of <option>lxc.hook.version</option>. If it
2138 is set to 1 then LXC_HOOK_SECTION will be set.
2139 </para></listitem>
2140 <listitem><para> LXC_HOOK_VERSION: the version of the hooks. This
2141 value is identical to the value of the container's
2142 <option>lxc.hook.version</option> config item. If it is set to 0 then
2143 old-style hooks are used. If it is set to 1 then new-style hooks are
2144 used. </para></listitem>
2145 <listitem><para> LXC_LOG_LEVEL: the container's log level. </para></listitem>
2146 <listitem><para> LXC_NAME: is the container's name. </para></listitem>
2147 <listitem><para> LXC_[NAMESPACE IDENTIFIER]_NS: path under
2148 /proc/PID/fd/ to a file descriptor referring to the container's
2149 namespace. For each preserved namespace type there will be a separate
2150 environment variable. These environment variables will only be set if
2151 <option>lxc.hook.version</option> is set to 1. </para></listitem>
2152 <listitem><para> LXC_ROOTFS_MOUNT: the path to the mounted root filesystem. </para></listitem>
2153 <listitem><para> LXC_ROOTFS_PATH: this is the lxc.rootfs.path entry
2154 for the container. Note this is likely not where the mounted rootfs is
2155 to be found, use LXC_ROOTFS_MOUNT for that. </para></listitem>
2156 <listitem><para> LXC_SRC_NAME: in the case of the clone hook, this is
2157 the original container's name. </para></listitem>
2158 </itemizedlist>
2159 </para>
2160 <para>
2161 Standard output from the hooks is logged at debug level.
2162 Standard error is not logged, but can be captured by the
2163 hook redirecting its standard error to standard output.
2164 </para>
2165 <variablelist>
2166 <varlistentry>
2167 <term>
2168 <option>lxc.hook.version</option>
2169 </term>
2170 <listitem>
2171 <para>
2172 To pass the arguments in new style via environment variables set to
2173 1 otherwise set to 0 to pass them as arguments.
2174 This setting affects all hooks arguments that were traditionally
2175 passed as arguments to the script. Specifically, it affects the
2176 container name, section (e.g. 'lxc', 'net') and hook type (e.g.
2177 'clone', 'mount', 'pre-mount') arguments. If new-style hooks are
2178 used then the arguments will be available as environment variables.
2179 The container name will be set in LXC_NAME. (This is set
2180 independently of the value used for this config item.) The section
2181 will be set in LXC_HOOK_SECTION and the hook type will be set in
2182 LXC_HOOK_TYPE.
2183 It also affects how the paths to file descriptors referring to the
2184 container's namespaces are passed. If set to 1 then for each
2185 namespace a separate environment variable LXC_[NAMESPACE
2186 IDENTIFIER]_NS will be set. If set to 0 then the paths will be
2187 passed as arguments to the stop hook.
2188 </para>
2189 </listitem>
2190 </varlistentry>
2191 </variablelist>
2192 <variablelist>
2193 <varlistentry>
2194 <term>
2195 <option>lxc.hook.pre-start</option>
2196 </term>
2197 <listitem>
2198 <para>
2199 A hook to be run in the host's namespace before the
2200 container ttys, consoles, or mounts are up.
2201 </para>
2202 </listitem>
2203 </varlistentry>
2204 </variablelist>
2205 <variablelist>
2206 <varlistentry>
2207 <term>
2208 <option>lxc.hook.pre-mount</option>
2209 </term>
2210 <listitem>
2211 <para>
2212 A hook to be run in the container's fs namespace but before
2213 the rootfs has been set up. This allows for manipulation
2214 of the rootfs, i.e. to mount an encrypted filesystem. Mounts
2215 done in this hook will not be reflected on the host (apart from
2216 mounts propagation), so they will be automatically cleaned up
2217 when the container shuts down.
2218 </para>
2219 </listitem>
2220 </varlistentry>
2221 </variablelist>
2222 <variablelist>
2223 <varlistentry>
2224 <term>
2225 <option>lxc.hook.mount</option>
2226 </term>
2227 <listitem>
2228 <para>
2229 A hook to be run in the container's namespace after
2230 mounting has been done, but before the pivot_root.
2231 </para>
2232 </listitem>
2233 </varlistentry>
2234 </variablelist>
2235 <variablelist>
2236 <varlistentry>
2237 <term>
2238 <option>lxc.hook.autodev</option>
2239 </term>
2240 <listitem>
2241 <para>
2242 A hook to be run in the container's namespace after
2243 mounting has been done and after any mount hooks have
2244 run, but before the pivot_root, if
2245 <option>lxc.autodev</option> == 1.
2246 The purpose of this hook is to assist in populating the
2247 /dev directory of the container when using the autodev
2248 option for systemd based containers. The container's /dev
2249 directory is relative to the
2250 ${<option>LXC_ROOTFS_MOUNT</option>} environment
2251 variable available when the hook is run.
2252 </para>
2253 </listitem>
2254 </varlistentry>
2255 </variablelist>
2256 <variablelist>
2257 <varlistentry>
2258 <term>
2259 <option>lxc.hook.start-host</option>
2260 </term>
2261 <listitem>
2262 <para>
2263 A hook to be run in the host's namespace after the
2264 container has been setup, and immediately before starting
2265 the container init.
2266 </para>
2267 </listitem>
2268 </varlistentry>
2269 </variablelist>
2270 <variablelist>
2271 <varlistentry>
2272 <term>
2273 <option>lxc.hook.start</option>
2274 </term>
2275 <listitem>
2276 <para>
2277 A hook to be run in the container's namespace immediately
2278 before executing the container's init. This requires the
2279 program to be available in the container.
2280 </para>
2281 </listitem>
2282 </varlistentry>
2283 </variablelist>
2284 <variablelist>
2285 <varlistentry>
2286 <term>
2287 <option>lxc.hook.stop</option>
2288 </term>
2289 <listitem>
2290 <para>
2291 A hook to be run in the host's namespace with references
2292 to the container's namespaces after the container has been shut
2293 down. For each namespace an extra argument is passed to the hook
2294 containing the namespace's type and a filename that can be used to
2295 obtain a file descriptor to the corresponding namespace, separated
2296 by a colon. The type is the name as it would appear in the
2297 <filename>/proc/PID/ns</filename> directory.
2298 For instance for the mount namespace the argument usually looks
2299 like <filename>mnt:/proc/PID/fd/12</filename>.
2300 </para>
2301 </listitem>
2302 </varlistentry>
2303 </variablelist>
2304 <variablelist>
2305 <varlistentry>
2306 <term>
2307 <option>lxc.hook.post-stop</option>
2308 </term>
2309 <listitem>
2310 <para>
2311 A hook to be run in the host's namespace after the
2312 container has been shut down.
2313 </para>
2314 </listitem>
2315 </varlistentry>
2316 </variablelist>
2317 <variablelist>
2318 <varlistentry>
2319 <term>
2320 <option>lxc.hook.clone</option>
2321 </term>
2322 <listitem>
2323 <para>
2324 A hook to be run when the container is cloned to a new one.
2325 See <citerefentry><refentrytitle><command>lxc-clone</command></refentrytitle>
2326 <manvolnum>1</manvolnum></citerefentry> for more information.
2327 </para>
2328 </listitem>
2329 </varlistentry>
2330 </variablelist>
2331 <variablelist>
2332 <varlistentry>
2333 <term>
2334 <option>lxc.hook.destroy</option>
2335 </term>
2336 <listitem>
2337 <para>
2338 A hook to be run when the container is destroyed.
2339 </para>
2340 </listitem>
2341 </varlistentry>
2342 </variablelist>
2343 </refsect2>
2344
2345 <refsect2>
2346 <title>Container hooks Environment Variables</title>
2347 <para>
2348 A number of environment variables are made available to the startup
2349 hooks to provide configuration information and assist in the
2350 functioning of the hooks. Not all variables are valid in all
2351 contexts. In particular, all paths are relative to the host system
2352 and, as such, not valid during the <option>lxc.hook.start</option> hook.
2353 </para>
2354 <variablelist>
2355 <varlistentry>
2356 <term>
2357 <option>LXC_NAME</option>
2358 </term>
2359 <listitem>
2360 <para>
2361 The LXC name of the container. Useful for logging messages
2362 in common log environments. [<option>-n</option>]
2363 </para>
2364 </listitem>
2365 </varlistentry>
2366 </variablelist>
2367 <variablelist>
2368 <varlistentry>
2369 <term>
2370 <option>LXC_CONFIG_FILE</option>
2371 </term>
2372 <listitem>
2373 <para>
2374 Host relative path to the container configuration file. This
2375 gives the container to reference the original, top level,
2376 configuration file for the container in order to locate any
2377 additional configuration information not otherwise made
2378 available. [<option>-f</option>]
2379 </para>
2380 </listitem>
2381 </varlistentry>
2382 </variablelist>
2383 <variablelist>
2384 <varlistentry>
2385 <term>
2386 <option>LXC_CONSOLE</option>
2387 </term>
2388 <listitem>
2389 <para>
2390 The path to the console output of the container if not NULL.
2391 [<option>-c</option>] [<option>lxc.console.path</option>]
2392 </para>
2393 </listitem>
2394 </varlistentry>
2395 </variablelist>
2396 <variablelist>
2397 <varlistentry>
2398 <term>
2399 <option>LXC_CONSOLE_LOGPATH</option>
2400 </term>
2401 <listitem>
2402 <para>
2403 The path to the console log output of the container if not NULL.
2404 [<option>-L</option>]
2405 </para>
2406 </listitem>
2407 </varlistentry>
2408 </variablelist>
2409 <variablelist>
2410 <varlistentry>
2411 <term>
2412 <option>LXC_ROOTFS_MOUNT</option>
2413 </term>
2414 <listitem>
2415 <para>
2416 The mount location to which the container is initially bound.
2417 This will be the host relative path to the container rootfs
2418 for the container instance being started and is where changes
2419 should be made for that instance.
2420 [<option>lxc.rootfs.mount</option>]
2421 </para>
2422 </listitem>
2423 </varlistentry>
2424 </variablelist>
2425 <variablelist>
2426 <varlistentry>
2427 <term>
2428 <option>LXC_ROOTFS_PATH</option>
2429 </term>
2430 <listitem>
2431 <para>
2432 The host relative path to the container root which has been
2433 mounted to the rootfs.mount location.
2434 [<option>lxc.rootfs.path</option>]
2435 </para>
2436 </listitem>
2437 </varlistentry>
2438 </variablelist>
2439 <variablelist>
2440 <varlistentry>
2441 <term>
2442 <option>LXC_SRC_NAME</option>
2443 </term>
2444 <listitem>
2445 <para>
2446 Only for the clone hook. Is set to the original container name.
2447 </para>
2448 </listitem>
2449 </varlistentry>
2450 </variablelist>
2451 <variablelist>
2452 <varlistentry>
2453 <term>
2454 <option>LXC_TARGET</option>
2455 </term>
2456 <listitem>
2457 <para>
2458 Only for the stop hook. Is set to "stop" for a container
2459 shutdown or "reboot" for a container reboot.
2460 </para>
2461 </listitem>
2462 </varlistentry>
2463 </variablelist>
2464 <variablelist>
2465 <varlistentry>
2466 <term>
2467 <option>LXC_CGNS_AWARE</option>
2468 </term>
2469 <listitem>
2470 <para>
2471 If unset, then this version of lxc is not aware of cgroup
2472 namespaces. If set, it will be set to 1, and lxc is aware
2473 of cgroup namespaces. Note this does not guarantee that
2474 cgroup namespaces are enabled in the kernel. This is used
2475 by the lxcfs mount hook.
2476 </para>
2477 </listitem>
2478 </varlistentry>
2479 </variablelist>
2480 </refsect2>
2481 <refsect2>
2482 <title>Logging</title>
2483 <para>
2484 Logging can be configured on a per-container basis. By default,
2485 depending upon how the lxc package was compiled, container startup
2486 is logged only at the ERROR level, and logged to a file named after
2487 the container (with '.log' appended) either under the container path,
2488 or under @LOGPATH@.
2489 </para>
2490 <para>
2491 Both the default log level and the log file can be specified in the
2492 container configuration file, overriding the default behavior. Note
2493 that the configuration file entries can in turn be overridden by the
2494 command line options to <command>lxc-start</command>.
2495 </para>
2496 <variablelist>
2497 <varlistentry>
2498 <term>
2499 <option>lxc.log.level</option>
2500 </term>
2501 <listitem>
2502 <para>
2503 The level at which to log. The log level is an integer in
2504 the range of 0..8 inclusive, where a lower number means more
2505 verbose debugging. In particular 0 = trace, 1 = debug, 2 =
2506 info, 3 = notice, 4 = warn, 5 = error, 6 = critical, 7 =
2507 alert, and 8 = fatal. If unspecified, the level defaults
2508 to 5 (error), so that only errors and above are logged.
2509 </para>
2510 <para>
2511 Note that when a script (such as either a hook script or a
2512 network interface up or down script) is called, the script's
2513 standard output is logged at level 1, debug.
2514 </para>
2515 </listitem>
2516 </varlistentry>
2517 <varlistentry>
2518 <term>
2519 <option>lxc.log.file</option>
2520 </term>
2521 <listitem>
2522 <para>
2523 The file to which logging info should be written.
2524 </para>
2525 </listitem>
2526 </varlistentry>
2527 <varlistentry>
2528 <term>
2529 <option>lxc.log.syslog</option>
2530 </term>
2531 <listitem>
2532 <para>
2533 Send logging info to syslog. It respects the log level defined in
2534 <command>lxc.log.level</command>. The argument should be the syslog
2535 facility to use, valid ones are: daemon, local0, local1, local2,
2536 local3, local4, local5, local5, local6, local7.
2537 </para>
2538 </listitem>
2539 </varlistentry>
2540 </variablelist>
2541 </refsect2>
2542
2543 <refsect2>
2544 <title>Autostart</title>
2545 <para>
2546 The autostart options support marking which containers should be
2547 auto-started and in what order. These options may be used by LXC tools
2548 directly or by external tooling provided by the distributions.
2549 </para>
2550
2551 <variablelist>
2552 <varlistentry>
2553 <term>
2554 <option>lxc.start.auto</option>
2555 </term>
2556 <listitem>
2557 <para>
2558 Whether the container should be auto-started.
2559 Valid values are 0 (off) and 1 (on).
2560 </para>
2561 </listitem>
2562 </varlistentry>
2563 <varlistentry>
2564 <term>
2565 <option>lxc.start.delay</option>
2566 </term>
2567 <listitem>
2568 <para>
2569 How long to wait (in seconds) after the container is
2570 started before starting the next one.
2571 </para>
2572 </listitem>
2573 </varlistentry>
2574 <varlistentry>
2575 <term>
2576 <option>lxc.start.order</option>
2577 </term>
2578 <listitem>
2579 <para>
2580 An integer used to sort the containers when auto-starting
2581 a series of containers at once. A lower value means an
2582 earlier start.
2583 </para>
2584 </listitem>
2585 </varlistentry>
2586 <varlistentry>
2587 <term>
2588 <option>lxc.monitor.unshare</option>
2589 </term>
2590 <listitem>
2591 <para>
2592 If not zero the mount namespace will be unshared from the host
2593 before initializing the container (before running any pre-start
2594 hooks). This requires the CAP_SYS_ADMIN capability at startup.
2595 Default is 0.
2596 </para>
2597 </listitem>
2598 </varlistentry>
2599 <varlistentry>
2600 <term>
2601 <option>lxc.monitor.signal.pdeath</option>
2602 </term>
2603 <listitem>
2604 <para>
2605 Set the signal to be sent to the container's init when the lxc
2606 monitor exits. By default it is set to SIGKILL which will cause
2607 all container processes to be killed when the lxc monitor process
2608 dies.
2609 To ensure that containers stay alive even if lxc monitor dies set
2610 this to 0.
2611 </para>
2612 </listitem>
2613 </varlistentry>
2614 <varlistentry>
2615 <term>
2616 <option>lxc.group</option>
2617 </term>
2618 <listitem>
2619 <para>
2620 A multi-value key (can be used multiple times) to put the
2621 container in a container group. Those groups can then be
2622 used (amongst other things) to start a series of related
2623 containers.
2624 </para>
2625 </listitem>
2626 </varlistentry>
2627 </variablelist>
2628 </refsect2>
2629
2630 <refsect2>
2631 <title>Autostart and System Boot</title>
2632 <para>
2633 Each container can be part of any number of groups or no group at all.
2634 Two groups are special. One is the NULL group, i.e. the container does
2635 not belong to any group. The other group is the "onboot" group.
2636 </para>
2637
2638 <para>
2639 When the system boots with the LXC service enabled, it will first
2640 attempt to boot any containers with lxc.start.auto == 1 that is a member
2641 of the "onboot" group. The startup will be in order of lxc.start.order.
2642 If an lxc.start.delay has been specified, that delay will be honored
2643 before attempting to start the next container to give the current
2644 container time to begin initialization and reduce overloading the host
2645 system. After starting the members of the "onboot" group, the LXC system
2646 will proceed to boot containers with lxc.start.auto == 1 which are not
2647 members of any group (the NULL group) and proceed as with the onboot
2648 group.
2649 </para>
2650
2651 </refsect2>
2652
2653 <refsect2>
2654 <title>Container Environment</title>
2655 <para>
2656 If you want to pass environment variables into the container (that
2657 is, environment variables which will be available to init and all of
2658 its descendents), you can use <command>lxc.environment</command>
2659 parameters to do so. Be careful that you do not pass in anything
2660 sensitive; any process in the container which doesn't have its
2661 environment scrubbed will have these variables available to it, and
2662 environment variables are always available via
2663 <command>/proc/PID/environ</command>.
2664 </para>
2665
2666 <para>
2667 This configuration parameter can be specified multiple times; once
2668 for each environment variable you wish to configure.
2669 </para>
2670
2671 <variablelist>
2672 <varlistentry>
2673 <term>
2674 <option>lxc.environment</option>
2675 </term>
2676 <listitem>
2677 <para>
2678 Specify an environment variable to pass into the container.
2679 Example:
2680 </para>
2681 <programlisting>
2682 lxc.environment = APP_ENV=production
2683 lxc.environment = SYSLOG_SERVER=192.0.2.42
2684 </programlisting>
2685 <para>
2686 It is possible to inherit host environment variables by setting the
2687 name of the variable without a "=" sign. For example:
2688 </para>
2689 <programlisting>
2690 lxc.environment = PATH
2691 </programlisting>
2692 </listitem>
2693 </varlistentry>
2694 </variablelist>
2695 </refsect2>
2696
2697 </refsect1>
2698
2699 <refsect1>
2700 <title>Examples</title>
2701 <para>
2702 In addition to the few examples given below, you will find
2703 some other examples of configuration file in @DOCDIR@/examples
2704 </para>
2705 <refsect2>
2706 <title>Network</title>
2707 <para>This configuration sets up a container to use a veth pair
2708 device with one side plugged to a bridge br0 (which has been
2709 configured before on the system by the administrator). The
2710 virtual network device visible in the container is renamed to
2711 eth0.</para>
2712 <programlisting>
2713 lxc.uts.name = myhostname
2714 lxc.net.0.type = veth
2715 lxc.net.0.flags = up
2716 lxc.net.0.link = br0
2717 lxc.net.0.name = eth0
2718 lxc.net.0.hwaddr = 4a:49:43:49:79:bf
2719 lxc.net.0.ipv4.address = 10.2.3.5/24 10.2.3.255
2720 lxc.net.0.ipv6.address = 2003:db8:1:0:214:1234:fe0b:3597
2721 </programlisting>
2722 </refsect2>
2723
2724 <refsect2>
2725 <title>UID/GID mapping</title>
2726 <para>This configuration will map both user and group ids in the
2727 range 0-9999 in the container to the ids 100000-109999 on the host.
2728 </para>
2729 <programlisting>
2730 lxc.idmap = u 0 100000 10000
2731 lxc.idmap = g 0 100000 10000
2732 </programlisting>
2733 </refsect2>
2734
2735 <refsect2>
2736 <title>Control group</title>
2737 <para>This configuration will setup several control groups for
2738 the application, cpuset.cpus restricts usage of the defined cpu,
2739 cpus.share prioritize the control group, devices.allow makes
2740 usable the specified devices.</para>
2741 <programlisting>
2742 lxc.cgroup.cpuset.cpus = 0,1
2743 lxc.cgroup.cpu.shares = 1234
2744 lxc.cgroup.devices.deny = a
2745 lxc.cgroup.devices.allow = c 1:3 rw
2746 lxc.cgroup.devices.allow = b 8:0 rw
2747 </programlisting>
2748 </refsect2>
2749
2750 <refsect2>
2751 <title>Complex configuration</title>
2752 <para>This example show a complex configuration making a complex
2753 network stack, using the control groups, setting a new hostname,
2754 mounting some locations and a changing root file system.</para>
2755 <programlisting>
2756 lxc.uts.name = complex
2757 lxc.net.0.type = veth
2758 lxc.net.0.flags = up
2759 lxc.net.0.link = br0
2760 lxc.net.0.hwaddr = 4a:49:43:49:79:bf
2761 lxc.net.0.ipv4.address = 10.2.3.5/24 10.2.3.255
2762 lxc.net.0.ipv6.address = 2003:db8:1:0:214:1234:fe0b:3597
2763 lxc.net.0.ipv6.address = 2003:db8:1:0:214:5432:feab:3588
2764 lxc.net.1.type = macvlan
2765 lxc.net.1.flags = up
2766 lxc.net.1.link = eth0
2767 lxc.net.1.hwaddr = 4a:49:43:49:79:bd
2768 lxc.net.1.ipv4.address = 10.2.3.4/24
2769 lxc.net.1.ipv4.address = 192.168.10.125/24
2770 lxc.net.1.ipv6.address = 2003:db8:1:0:214:1234:fe0b:3596
2771 lxc.net.2.type = phys
2772 lxc.net.2.flags = up
2773 lxc.net.2.link = dummy0
2774 lxc.net.2.hwaddr = 4a:49:43:49:79:ff
2775 lxc.net.2.ipv4.address = 10.2.3.6/24
2776 lxc.net.2.ipv6.address = 2003:db8:1:0:214:1234:fe0b:3297
2777 lxc.cgroup.cpuset.cpus = 0,1
2778 lxc.cgroup.cpu.shares = 1234
2779 lxc.cgroup.devices.deny = a
2780 lxc.cgroup.devices.allow = c 1:3 rw
2781 lxc.cgroup.devices.allow = b 8:0 rw
2782 lxc.mount.fstab = /etc/fstab.complex
2783 lxc.mount.entry = /lib /root/myrootfs/lib none ro,bind 0 0
2784 lxc.rootfs.path = dir:/mnt/rootfs.complex
2785 lxc.cap.drop = sys_module mknod setuid net_raw
2786 lxc.cap.drop = mac_override
2787 </programlisting>
2788 </refsect2>
2789
2790 </refsect1>
2791
2792 <refsect1>
2793 <title>See Also</title>
2794 <simpara>
2795 <citerefentry>
2796 <refentrytitle><command>chroot</command></refentrytitle>
2797 <manvolnum>1</manvolnum>
2798 </citerefentry>,
2799
2800 <citerefentry>
2801 <refentrytitle><command>pivot_root</command></refentrytitle>
2802 <manvolnum>8</manvolnum>
2803 </citerefentry>,
2804
2805 <citerefentry>
2806 <refentrytitle><filename>fstab</filename></refentrytitle>
2807 <manvolnum>5</manvolnum>
2808 </citerefentry>,
2809
2810 <citerefentry>
2811 <refentrytitle><filename>capabilities</filename></refentrytitle>
2812 <manvolnum>7</manvolnum>
2813 </citerefentry>
2814 </simpara>
2815 </refsect1>
2816
2817 &seealso;
2818
2819 <refsect1>
2820 <title>Author</title>
2821 <para>Daniel Lezcano <email>daniel.lezcano@free.fr</email></para>
2822 </refsect1>
2823
2824 </refentry>
2825
2826 <!-- Keep this comment at the end of the file
2827 Local variables:
2828 mode: sgml
2829 sgml-omittag:t
2830 sgml-shorttag:t
2831 sgml-minimize-attributes:nil
2832 sgml-always-quote-attributes:t
2833 sgml-indent-step:2
2834 sgml-indent-data:t
2835 sgml-parent-document:nil
2836 sgml-default-dtd-file:nil
2837 sgml-exposed-tags:nil
2838 sgml-local-catalogs:nil
2839 sgml-local-ecat-files:nil
2840 End:
2841 -->