docs: add memory and swap memory usage examples
| ... | ... |
@@ -427,36 +427,37 @@ the `--security-opt` flag. For example, you can specify the MCS/MLS level, a |
| 427 | 427 |
requirement for MLS systems. Specifying the level in the following command |
| 428 | 428 |
allows you to share the same content between containers. |
| 429 | 429 |
|
| 430 |
- # docker run --security-opt label:level:s0:c100,c200 -i -t fedora bash |
|
| 430 |
+ $ sudo docker run --security-opt label:level:s0:c100,c200 -i -t fedora bash |
|
| 431 | 431 |
|
| 432 | 432 |
An MLS example might be: |
| 433 | 433 |
|
| 434 |
- # docker run --security-opt label:level:TopSecret -i -t rhel7 bash |
|
| 434 |
+ $ sudo docker run --security-opt label:level:TopSecret -i -t rhel7 bash |
|
| 435 | 435 |
|
| 436 | 436 |
To disable the security labeling for this container versus running with the |
| 437 | 437 |
`--permissive` flag, use the following command: |
| 438 | 438 |
|
| 439 |
- # docker run --security-opt label:disable -i -t fedora bash |
|
| 439 |
+ $ sudo docker run --security-opt label:disable -i -t fedora bash |
|
| 440 | 440 |
|
| 441 | 441 |
If you want a tighter security policy on the processes within a container, |
| 442 | 442 |
you can specify an alternate type for the container. You could run a container |
| 443 | 443 |
that is only allowed to listen on Apache ports by executing the following |
| 444 | 444 |
command: |
| 445 | 445 |
|
| 446 |
- # docker run --security-opt label:type:svirt_apache_t -i -t centos bash |
|
| 446 |
+ $ sudo docker run --security-opt label:type:svirt_apache_t -i -t centos bash |
|
| 447 | 447 |
|
| 448 | 448 |
Note: |
| 449 | 449 |
|
| 450 | 450 |
You would have to write policy defining a `svirt_apache_t` type. |
| 451 | 451 |
|
| 452 |
-## Runtime constraints on CPU and memory |
|
| 452 |
+## Runtime constraints on resources |
|
| 453 | 453 |
|
| 454 | 454 |
The operator can also adjust the performance parameters of the |
| 455 | 455 |
container: |
| 456 | 456 |
|
| 457 |
- -m="": Memory limit (format: <number><optional unit>, where unit = b, k, m or g) |
|
| 457 |
+ -m, --memory="": Memory limit (format: <number><optional unit>, where unit = b, k, m or g) |
|
| 458 | 458 |
-memory-swap="": Total memory limit (memory + swap, format: <number><optional unit>, where unit = b, k, m or g) |
| 459 |
- -c, --cpu-shares=0 CPU shares (relative weight) |
|
| 459 |
+ -c, --cpu-shares=0: CPU shares (relative weight) |
|
| 460 |
+ --cpuset-cpus="": CPUs in which to allow execution (0-3, 0,1) |
|
| 460 | 461 |
|
| 461 | 462 |
### Memory constraints |
| 462 | 463 |
|
| ... | ... |
@@ -508,6 +509,31 @@ We have four ways to set memory usage: |
| 508 | 508 |
</tbody> |
| 509 | 509 |
</table> |
| 510 | 510 |
|
| 511 |
+Examples: |
|
| 512 |
+ |
|
| 513 |
+ $ sudo docker run -ti ubuntu:14.04 /bin/bash |
|
| 514 |
+ |
|
| 515 |
+We set nothing about memory, this means the processes in the container can use |
|
| 516 |
+as much memory and swap memory as they need. |
|
| 517 |
+ |
|
| 518 |
+ $ sudo docker run -ti -m 300M --memory-swap -1 ubuntu:14.04 /bin/bash |
|
| 519 |
+ |
|
| 520 |
+We set memory limit and disabled swap memory limit, this means the processes in |
|
| 521 |
+the container can use 300M memory and as much swap memory as they need (if the |
|
| 522 |
+host supports swap memory). |
|
| 523 |
+ |
|
| 524 |
+ $ sudo docker run -ti -m 300M ubuntu:14.04 /bin/bash |
|
| 525 |
+ |
|
| 526 |
+We set memory limit only, this means the processes in the container can use |
|
| 527 |
+300M memory and 300M swap memory, by default, the total virtual memory size |
|
| 528 |
+(--memory-swap) will be set as double of memory, in this case, memory + swap |
|
| 529 |
+would be 2*300M, so processes can use 300M swap memory as well. |
|
| 530 |
+ |
|
| 531 |
+ $ sudo docker run -ti -m 300M --memory-swap 1G ubuntu:14.04 /bin/bash |
|
| 532 |
+ |
|
| 533 |
+We set both memory and swap memory, so the processes in the container can use |
|
| 534 |
+300M memory and 700M swap memory. |
|
| 535 |
+ |
|
| 511 | 536 |
### CPU share constraint |
| 512 | 537 |
|
| 513 | 538 |
By default, all containers get the same proportion of CPU cycles. This proportion |
| ... | ... |
@@ -543,6 +569,20 @@ division of CPU shares: |
| 543 | 543 |
101 {C1} 1 100% of CPU1
|
| 544 | 544 |
102 {C1} 2 100% of CPU2
|
| 545 | 545 |
|
| 546 |
+### Cpuset constraint |
|
| 547 |
+ |
|
| 548 |
+We can set cpus in which to allow execution for containers. |
|
| 549 |
+ |
|
| 550 |
+Examples: |
|
| 551 |
+ |
|
| 552 |
+ $ sudo docker run -ti --cpuset-cpus="1,3" ubuntu:14.04 /bin/bash |
|
| 553 |
+ |
|
| 554 |
+This means processes in container can be executed on cpu 1 and cpu 3. |
|
| 555 |
+ |
|
| 556 |
+ $ sudo docker run -ti --cpuset-cpus="0-2" ubuntu:14.04 /bin/bash |
|
| 557 |
+ |
|
| 558 |
+This means processes in container can be executed on cpu 0, cpu 1 and cpu 2. |
|
| 559 |
+ |
|
| 546 | 560 |
## Runtime privilege, Linux capabilities, and LXC configuration |
| 547 | 561 |
|
| 548 | 562 |
--cap-add: Add Linux capabilities |
| ... | ... |
@@ -599,18 +639,18 @@ operator wants to have all capabilities but `MKNOD` they could use: |
| 599 | 599 |
For interacting with the network stack, instead of using `--privileged` they |
| 600 | 600 |
should use `--cap-add=NET_ADMIN` to modify the network interfaces. |
| 601 | 601 |
|
| 602 |
- $ docker run -t -i --rm ubuntu:14.04 ip link add dummy0 type dummy |
|
| 602 |
+ $ sudo docker run -t -i --rm ubuntu:14.04 ip link add dummy0 type dummy |
|
| 603 | 603 |
RTNETLINK answers: Operation not permitted |
| 604 |
- $ docker run -t -i --rm --cap-add=NET_ADMIN ubuntu:14.04 ip link add dummy0 type dummy |
|
| 604 |
+ $ sudo docker run -t -i --rm --cap-add=NET_ADMIN ubuntu:14.04 ip link add dummy0 type dummy |
|
| 605 | 605 |
|
| 606 | 606 |
To mount a FUSE based filesystem, you need to combine both `--cap-add` and |
| 607 | 607 |
`--device`: |
| 608 | 608 |
|
| 609 |
- $ docker run --rm -it --cap-add SYS_ADMIN sshfs sshfs sven@10.10.10.20:/home/sven /mnt |
|
| 609 |
+ $ sudo docker run --rm -it --cap-add SYS_ADMIN sshfs sshfs sven@10.10.10.20:/home/sven /mnt |
|
| 610 | 610 |
fuse: failed to open /dev/fuse: Operation not permitted |
| 611 |
- $ docker run --rm -it --device /dev/fuse sshfs sshfs sven@10.10.10.20:/home/sven /mnt |
|
| 611 |
+ $ sudo docker run --rm -it --device /dev/fuse sshfs sshfs sven@10.10.10.20:/home/sven /mnt |
|
| 612 | 612 |
fusermount: mount failed: Operation not permitted |
| 613 |
- $ docker run --rm -it --cap-add SYS_ADMIN --device /dev/fuse sshfs |
|
| 613 |
+ $ sudo docker run --rm -it --cap-add SYS_ADMIN --device /dev/fuse sshfs |
|
| 614 | 614 |
# sshfs sven@10.10.10.20:/home/sven /mnt |
| 615 | 615 |
The authenticity of host '10.10.10.20 (10.10.10.20)' can't be established. |
| 616 | 616 |
ECDSA key fingerprint is 25:34:85:75:25:b0:17:46:05:19:04:93:b5:dd:5f:c6. |