]> git.proxmox.com Git - pve-docs.git/blame_incremental - pct.adoc
fix typo
[pve-docs.git] / pct.adoc
... / ...
CommitLineData
1[[chapter_pct]]
2ifdef::manvolnum[]
3pct(1)
4======
5include::attributes.txt[]
6:pve-toplevel:
7
8NAME
9----
10
11pct - Tool to manage Linux Containers (LXC) on Proxmox VE
12
13
14SYNOPSIS
15--------
16
17include::pct.1-synopsis.adoc[]
18
19DESCRIPTION
20-----------
21endif::manvolnum[]
22
23ifndef::manvolnum[]
24Proxmox Container Toolkit
25=========================
26include::attributes.txt[]
27:pve-toplevel:
28endif::manvolnum[]
29ifdef::wiki[]
30:title: Linux Container
31endif::wiki[]
32
33Containers are a lightweight alternative to fully virtualized
34VMs. Instead of emulating a complete Operating System (OS), containers
35simply use the OS of the host they run on. This implies that all
36containers use the same kernel, and that they can access resources
37from the host directly.
38
39This is great because containers do not waste CPU power nor memory due
40to kernel emulation. Container run-time costs are close to zero and
41usually negligible. But there are also some drawbacks you need to
42consider:
43
44* You can only run Linux based OS inside containers, i.e. it is not
45 possible to run FreeBSD or MS Windows inside.
46
47* For security reasons, access to host resources needs to be
48 restricted. This is done with AppArmor, SecComp filters and other
49 kernel features. Be prepared that some syscalls are not allowed
50 inside containers.
51
52{pve} uses https://linuxcontainers.org/[LXC] as underlying container
53technology. We consider LXC as low-level library, which provides
54countless options. It would be too difficult to use those tools
55directly. Instead, we provide a small wrapper called `pct`, the
56"Proxmox Container Toolkit".
57
58The toolkit is tightly coupled with {pve}. That means that it is aware
59of the cluster setup, and it can use the same network and storage
60resources as fully virtualized VMs. You can even use the {pve}
61firewall, or manage containers using the HA framework.
62
63Our primary goal is to offer an environment as one would get from a
64VM, but without the additional overhead. We call this "System
65Containers".
66
67NOTE: If you want to run micro-containers (with docker, rkt, ...), it
68is best to run them inside a VM.
69
70
71Security Considerations
72-----------------------
73
74Containers use the same kernel as the host, so there is a big attack
75surface for malicious users. You should consider this fact if you
76provide containers to totally untrusted people. In general, fully
77virtualized VMs provide better isolation.
78
79The good news is that LXC uses many kernel security features like
80AppArmor, CGroups and PID and user namespaces, which makes containers
81usage quite secure. We distinguish two types of containers:
82
83
84Privileged Containers
85~~~~~~~~~~~~~~~~~~~~~
86
87Security is done by dropping capabilities, using mandatory access
88control (AppArmor), SecComp filters and namespaces. The LXC team
89considers this kind of container as unsafe, and they will not consider
90new container escape exploits to be security issues worthy of a CVE
91and quick fix. So you should use this kind of containers only inside a
92trusted environment, or when no untrusted task is running as root in
93the container.
94
95
96Unprivileged Containers
97~~~~~~~~~~~~~~~~~~~~~~~
98
99This kind of containers use a new kernel feature called user
100namespaces. The root UID 0 inside the container is mapped to an
101unprivileged user outside the container. This means that most security
102issues (container escape, resource abuse, ...) in those containers
103will affect a random unprivileged user, and so would be a generic
104kernel security bug rather than an LXC issue. The LXC team thinks
105unprivileged containers are safe by design.
106
107[[pct_configuration]]
108Configuration
109-------------
110
111The `/etc/pve/lxc/<CTID>.conf` file stores container configuration,
112where `<CTID>` is the numeric ID of the given container. Like all
113other files stored inside `/etc/pve/`, they get automatically
114replicated to all other cluster nodes.
115
116NOTE: CTIDs < 100 are reserved for internal purposes, and CTIDs need to be
117unique cluster wide.
118
119.Example Container Configuration
120----
121ostype: debian
122arch: amd64
123hostname: www
124memory: 512
125swap: 512
126net0: bridge=vmbr0,hwaddr=66:64:66:64:64:36,ip=dhcp,name=eth0,type=veth
127rootfs: local:107/vm-107-disk-1.raw,size=7G
128----
129
130Those configuration files are simple text files, and you can edit them
131using a normal text editor (`vi`, `nano`, ...). This is sometimes
132useful to do small corrections, but keep in mind that you need to
133restart the container to apply such changes.
134
135For that reason, it is usually better to use the `pct` command to
136generate and modify those files, or do the whole thing using the GUI.
137Our toolkit is smart enough to instantaneously apply most changes to
138running containers. This feature is called "hot plug", and there is no
139need to restart the container in that case.
140
141
142File Format
143~~~~~~~~~~~
144
145Container configuration files use a simple colon separated key/value
146format. Each line has the following format:
147
148-----
149# this is a comment
150OPTION: value
151-----
152
153Blank lines in those files are ignored, and lines starting with a `#`
154character are treated as comments and are also ignored.
155
156It is possible to add low-level, LXC style configuration directly, for
157example:
158
159 lxc.init_cmd: /sbin/my_own_init
160
161or
162
163 lxc.init_cmd = /sbin/my_own_init
164
165Those settings are directly passed to the LXC low-level tools.
166
167
168[[pct_snapshots]]
169Snapshots
170~~~~~~~~~
171
172When you create a snapshot, `pct` stores the configuration at snapshot
173time into a separate snapshot section within the same configuration
174file. For example, after creating a snapshot called ``testsnapshot'',
175your configuration file will look like this:
176
177.Container configuration with snapshot
178----
179memory: 512
180swap: 512
181parent: testsnaphot
182...
183
184[testsnaphot]
185memory: 512
186swap: 512
187snaptime: 1457170803
188...
189----
190
191There are a few snapshot related properties like `parent` and
192`snaptime`. The `parent` property is used to store the parent/child
193relationship between snapshots. `snaptime` is the snapshot creation
194time stamp (Unix epoch).
195
196
197Guest Operating System Configuration
198~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
199
200We normally try to detect the operating system type inside the
201container, and then modify some files inside the container to make
202them work as expected. Here is a short list of things we do at
203container startup:
204
205set /etc/hostname:: to set the container name
206
207modify /etc/hosts:: to allow lookup of the local hostname
208
209network setup:: pass the complete network setup to the container
210
211configure DNS:: pass information about DNS servers
212
213adapt the init system:: for example, fix the number of spawned getty processes
214
215set the root password:: when creating a new container
216
217rewrite ssh_host_keys:: so that each container has unique keys
218
219randomize crontab:: so that cron does not start at the same time on all containers
220
221Changes made by {PVE} are enclosed by comment markers:
222
223----
224# --- BEGIN PVE ---
225<data>
226# --- END PVE ---
227----
228
229Those markers will be inserted at a reasonable location in the
230file. If such a section already exists, it will be updated in place
231and will not be moved.
232
233Modification of a file can be prevented by adding a `.pve-ignore.`
234file for it. For instance, if the file `/etc/.pve-ignore.hosts`
235exists then the `/etc/hosts` file will not be touched. This can be a
236simple empty file creatd via:
237
238 # touch /etc/.pve-ignore.hosts
239
240Most modifications are OS dependent, so they differ between different
241distributions and versions. You can completely disable modifications
242by manually setting the `ostype` to `unmanaged`.
243
244OS type detection is done by testing for certain files inside the
245container:
246
247Ubuntu:: inspect /etc/lsb-release (`DISTRIB_ID=Ubuntu`)
248
249Debian:: test /etc/debian_version
250
251Fedora:: test /etc/fedora-release
252
253RedHat or CentOS:: test /etc/redhat-release
254
255ArchLinux:: test /etc/arch-release
256
257Alpine:: test /etc/alpine-release
258
259Gentoo:: test /etc/gentoo-release
260
261NOTE: Container start fails if the configured `ostype` differs from the auto
262detected type.
263
264
265[[pct_options]]
266Options
267~~~~~~~
268
269include::pct.conf.5-opts.adoc[]
270
271
272[[pct_container_images]]
273Container Images
274----------------
275
276Container images, sometimes also referred to as ``templates'' or
277``appliances'', are `tar` archives which contain everything to run a
278container. You can think of it as a tidy container backup. Like most
279modern container toolkits, `pct` uses those images when you create a
280new container, for example:
281
282 pct create 999 local:vztmpl/debian-8.0-standard_8.0-1_amd64.tar.gz
283
284{pve} itself ships a set of basic templates for most common
285operating systems, and you can download them using the `pveam` (short
286for {pve} Appliance Manager) command line utility. You can also
287download https://www.turnkeylinux.org/[TurnKey Linux] containers using
288that tool (or the graphical user interface).
289
290Our image repositories contain a list of available images, and there
291is a cron job run each day to download that list. You can trigger that
292update manually with:
293
294 pveam update
295
296After that you can view the list of available images using:
297
298 pveam available
299
300You can restrict this large list by specifying the `section` you are
301interested in, for example basic `system` images:
302
303.List available system images
304----
305# pveam available --section system
306system archlinux-base_2015-24-29-1_x86_64.tar.gz
307system centos-7-default_20160205_amd64.tar.xz
308system debian-6.0-standard_6.0-7_amd64.tar.gz
309system debian-7.0-standard_7.0-3_amd64.tar.gz
310system debian-8.0-standard_8.0-1_amd64.tar.gz
311system ubuntu-12.04-standard_12.04-1_amd64.tar.gz
312system ubuntu-14.04-standard_14.04-1_amd64.tar.gz
313system ubuntu-15.04-standard_15.04-1_amd64.tar.gz
314system ubuntu-15.10-standard_15.10-1_amd64.tar.gz
315----
316
317Before you can use such a template, you need to download them into one
318of your storages. You can simply use storage `local` for that
319purpose. For clustered installations, it is preferred to use a shared
320storage so that all nodes can access those images.
321
322 pveam download local debian-8.0-standard_8.0-1_amd64.tar.gz
323
324You are now ready to create containers using that image, and you can
325list all downloaded images on storage `local` with:
326
327----
328# pveam list local
329local:vztmpl/debian-8.0-standard_8.0-1_amd64.tar.gz 190.20MB
330----
331
332The above command shows you the full {pve} volume identifiers. They include
333the storage name, and most other {pve} commands can use them. For
334example you can delete that image later with:
335
336 pveam remove local:vztmpl/debian-8.0-standard_8.0-1_amd64.tar.gz
337
338
339[[pct_container_storage]]
340Container Storage
341-----------------
342
343Traditional containers use a very simple storage model, only allowing
344a single mount point, the root file system. This was further
345restricted to specific file system types like `ext4` and `nfs`.
346Additional mounts are often done by user provided scripts. This turned
347out to be complex and error prone, so we try to avoid that now.
348
349Our new LXC based container model is more flexible regarding
350storage. First, you can have more than a single mount point. This
351allows you to choose a suitable storage for each application. For
352example, you can use a relatively slow (and thus cheap) storage for
353the container root file system. Then you can use a second mount point
354to mount a very fast, distributed storage for your database
355application.
356
357The second big improvement is that you can use any storage type
358supported by the {pve} storage library. That means that you can store
359your containers on local `lvmthin` or `zfs`, shared `iSCSI` storage,
360or even on distributed storage systems like `ceph`. It also enables us
361to use advanced storage features like snapshots and clones. `vzdump`
362can also use the snapshot feature to provide consistent container
363backups.
364
365Last but not least, you can also mount local devices directly, or
366mount local directories using bind mounts. That way you can access
367local storage inside containers with zero overhead. Such bind mounts
368also provide an easy way to share data between different containers.
369
370
371Mount Points
372~~~~~~~~~~~~
373
374The root mount point is configured with the `rootfs` property, and you can
375configure up to 10 additional mount points. The corresponding options
376are called `mp0` to `mp9`, and they can contain the following setting:
377
378include::pct-mountpoint-opts.adoc[]
379
380Currently there are basically three types of mount points: storage backed
381mount points, bind mounts and device mounts.
382
383.Typical container `rootfs` configuration
384----
385rootfs: thin1:base-100-disk-1,size=8G
386----
387
388
389Storage Backed Mount Points
390^^^^^^^^^^^^^^^^^^^^^^^^^^^
391
392Storage backed mount points are managed by the {pve} storage subsystem and come
393in three different flavors:
394
395- Image based: these are raw images containing a single ext4 formatted file
396 system.
397- ZFS subvolumes: these are technically bind mounts, but with managed storage,
398 and thus allow resizing and snapshotting.
399- Directories: passing `size=0` triggers a special case where instead of a raw
400 image a directory is created.
401
402
403Bind Mount Points
404^^^^^^^^^^^^^^^^^
405
406Bind mounts allow you to access arbitrary directories from your Proxmox VE host
407inside a container. Some potential use cases are:
408
409- Accessing your home directory in the guest
410- Accessing an USB device directory in the guest
411- Accessing an NFS mount from the host in the guest
412
413Bind mounts are considered to not be managed by the storage subsystem, so you
414cannot make snapshots or deal with quotas from inside the container. With
415unprivileged containers you might run into permission problems caused by the
416user mapping and cannot use ACLs.
417
418NOTE: The contents of bind mount points are not backed up when using `vzdump`.
419
420WARNING: For security reasons, bind mounts should only be established
421using source directories especially reserved for this purpose, e.g., a
422directory hierarchy under `/mnt/bindmounts`. Never bind mount system
423directories like `/`, `/var` or `/etc` into a container - this poses a
424great security risk.
425
426NOTE: The bind mount source path must not contain any symlinks.
427
428For example, to make the directory `/mnt/bindmounts/shared` accessible in the
429container with ID `100` under the path `/shared`, use a configuration line like
430`mp0: /mnt/bindmounts/shared,mp=/shared` in `/etc/pve/lxc/100.conf`.
431Alternatively, use `pct set 100 -mp0 /mnt/bindmounts/shared,mp=/shared` to
432achieve the same result.
433
434
435Device Mount Points
436^^^^^^^^^^^^^^^^^^^
437
438Device mount points allow to mount block devices of the host directly into the
439container. Similar to bind mounts, device mounts are not managed by {PVE}'s
440storage subsystem, but the `quota` and `acl` options will be honored.
441
442NOTE: Device mount points should only be used under special circumstances. In
443most cases a storage backed mount point offers the same performance and a lot
444more features.
445
446NOTE: The contents of device mount points are not backed up when using `vzdump`.
447
448
449FUSE Mounts
450~~~~~~~~~~~
451
452WARNING: Because of existing issues in the Linux kernel's freezer
453subsystem the usage of FUSE mounts inside a container is strongly
454advised against, as containers need to be frozen for suspend or
455snapshot mode backups.
456
457If FUSE mounts cannot be replaced by other mounting mechanisms or storage
458technologies, it is possible to establish the FUSE mount on the Proxmox host
459and use a bind mount point to make it accessible inside the container.
460
461
462Using Quotas Inside Containers
463~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
464
465Quotas allow to set limits inside a container for the amount of disk
466space that each user can use. This only works on ext4 image based
467storage types and currently does not work with unprivileged
468containers.
469
470Activating the `quota` option causes the following mount options to be
471used for a mount point:
472`usrjquota=aquota.user,grpjquota=aquota.group,jqfmt=vfsv0`
473
474This allows quotas to be used like you would on any other system. You
475can initialize the `/aquota.user` and `/aquota.group` files by running
476
477----
478quotacheck -cmug /
479quotaon /
480----
481
482and edit the quotas via the `edquota` command. Refer to the documentation
483of the distribution running inside the container for details.
484
485NOTE: You need to run the above commands for every mount point by passing
486the mount point's path instead of just `/`.
487
488
489Using ACLs Inside Containers
490~~~~~~~~~~~~~~~~~~~~~~~~~~~~
491
492The standard Posix **A**ccess **C**ontrol **L**ists are also available inside containers.
493ACLs allow you to set more detailed file ownership than the traditional user/
494group/others model.
495
496
497[[pct_container_network]]
498Container Network
499-----------------
500
501You can configure up to 10 network interfaces for a single
502container. The corresponding options are called `net0` to `net9`, and
503they can contain the following setting:
504
505include::pct-network-opts.adoc[]
506
507
508Backup and Restore
509------------------
510
511
512Container Backup
513~~~~~~~~~~~~~~~~
514
515It is possible to use the `vzdump` tool for container backup. Please
516refer to the `vzdump` manual page for details.
517
518
519Restoring Container Backups
520~~~~~~~~~~~~~~~~~~~~~~~~~~~
521
522Restoring container backups made with `vzdump` is possible using the
523`pct restore` command. By default, `pct restore` will attempt to restore as much
524of the backed up container configuration as possible. It is possible to override
525the backed up configuration by manually setting container options on the command
526line (see the `pct` manual page for details).
527
528NOTE: `pvesm extractconfig` can be used to view the backed up configuration
529contained in a vzdump archive.
530
531There are two basic restore modes, only differing by their handling of mount
532points:
533
534
535``Simple'' Restore Mode
536^^^^^^^^^^^^^^^^^^^^^^^
537
538If neither the `rootfs` parameter nor any of the optional `mpX` parameters
539are explicitly set, the mount point configuration from the backed up
540configuration file is restored using the following steps:
541
542. Extract mount points and their options from backup
543. Create volumes for storage backed mount points (on storage provided with the
544`storage` parameter, or default local storage if unset)
545. Extract files from backup archive
546. Add bind and device mount points to restored configuration (limited to root user)
547
548NOTE: Since bind and device mount points are never backed up, no files are
549restored in the last step, but only the configuration options. The assumption
550is that such mount points are either backed up with another mechanism (e.g.,
551NFS space that is bind mounted into many containers), or not intended to be
552backed up at all.
553
554This simple mode is also used by the container restore operations in the web
555interface.
556
557
558``Advanced'' Restore Mode
559^^^^^^^^^^^^^^^^^^^^^^^^^
560
561By setting the `rootfs` parameter (and optionally, any combination of `mpX`
562parameters), the `pct restore` command is automatically switched into an
563advanced mode. This advanced mode completely ignores the `rootfs` and `mpX`
564configuration options contained in the backup archive, and instead only
565uses the options explicitly provided as parameters.
566
567This mode allows flexible configuration of mount point settings at restore time,
568for example:
569
570* Set target storages, volume sizes and other options for each mount point
571individually
572* Redistribute backed up files according to new mount point scheme
573* Restore to device and/or bind mount points (limited to root user)
574
575
576Managing Containers with `pct`
577------------------------------
578
579`pct` is the tool to manage Linux Containers on {pve}. You can create
580and destroy containers, and control execution (start, stop, migrate,
581...). You can use pct to set parameters in the associated config file,
582like network configuration or memory limits.
583
584
585CLI Usage Examples
586~~~~~~~~~~~~~~~~~~
587
588Create a container based on a Debian template (provided you have
589already downloaded the template via the web interface)
590
591 pct create 100 /var/lib/vz/template/cache/debian-8.0-standard_8.0-1_amd64.tar.gz
592
593Start container 100
594
595 pct start 100
596
597Start a login session via getty
598
599 pct console 100
600
601Enter the LXC namespace and run a shell as root user
602
603 pct enter 100
604
605Display the configuration
606
607 pct config 100
608
609Add a network interface called `eth0`, bridged to the host bridge `vmbr0`,
610set the address and gateway, while it's running
611
612 pct set 100 -net0 name=eth0,bridge=vmbr0,ip=192.168.15.147/24,gw=192.168.15.1
613
614Reduce the memory of the container to 512MB
615
616 pct set 100 -memory 512
617
618
619Obtaining Debugging Logs
620~~~~~~~~~~~~~~~~~~~~~~~~
621
622In case `pct start` is unable to start a specific container, it might be
623helpful to collect debugging output by running `lxc-start` (replace `ID` with
624the container's ID):
625
626 lxc-start -n ID -F -l DEBUG -o /tmp/lxc-ID.log
627
628This command will attempt to start the container in foreground mode, to stop the container run `pct shutdown ID` or `pct stop ID` in a second terminal.
629
630The collected debug log is written to `/tmp/lxc-ID.log`.
631
632NOTE: If you have changed the container's configuration since the last start
633attempt with `pct start`, you need to run `pct start` at least once to also
634update the configuration used by `lxc-start`.
635
636
637Files
638------
639
640`/etc/pve/lxc/<CTID>.conf`::
641
642Configuration file for the container '<CTID>'.
643
644
645Container Advantages
646--------------------
647
648* Simple, and fully integrated into {pve}. Setup looks similar to a normal
649 VM setup.
650
651** Storage (ZFS, LVM, NFS, Ceph, ...)
652
653** Network
654
655** Authentication
656
657** Cluster
658
659* Fast: minimal overhead, as fast as bare metal
660
661* High density (perfect for idle workloads)
662
663* REST API
664
665* Direct hardware access
666
667
668Technology Overview
669-------------------
670
671* Integrated into {pve} graphical user interface (GUI)
672
673* LXC (https://linuxcontainers.org/)
674
675* lxcfs to provide containerized /proc file system
676
677* AppArmor
678
679* CRIU: for live migration (planned)
680
681* We use latest available kernels (4.4.X)
682
683* Image based deployment (templates)
684
685* Container setup from host (network, DNS, storage, ...)
686
687
688ifdef::manvolnum[]
689include::pve-copyright.adoc[]
690endif::manvolnum[]
691
692
693
694
695
696
697