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