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