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