• Setting resource limits
  • Sharing container memroy
  • Setting users, permissions, and administrative privileges
  • Granting access to specific Linux features
  • Working with SELinux and AppArmor

image.png

6.1 Setting resource allowance

6.1.1 Memory limits

  1. docker container run -d --name ch6_mariadb \
  2. --memory 256m \
  3. --cpu-shares 1024 \
  4. --cap-drop net_raw \
  5. -e MYSQL_ROOT_PASSWORD=test \
  6. mariadb:5.5

6.1.2 CPU

  1. docker container run -d -P --name ch6_wordpress \
  2. --memory 512m \
  3. # sets a relative process weight
  4. --cpu-shares 512 \
  5. --cap-drop net_raw \
  6. --link ch6_mariadb:mysql \
  7. -e WORDPRESS_DB_PASSWORD=test \
  8. wordpress:5.0.0-php7.2-apache
  1. docker container run -d -P --name ch6_wordpress \
  2. --memory 512m
  3. --cpus 0.75 \
  4. --cap-drop net_raw \
  5. --link ch6_mariadb:mysql \
  6. -e WORDPRESS_DB_PASSWORD=test \
  7. wordpress:5.0.0-php7.2-apache
  1. docker container run -d \
  2. --cpuset-cpus 0 \
  3. --name ch6_stresser dockerinaction/ch6_stresser
  4. docker container run -it --rm dockerinaction/ch6_htop

6.1.3 Access to devices

  1. docker container run -it --rm \
  2. --device /dev/video0:/dev/video0 \
  3. ubuntu:16.0.4 ls -al /dev

6.2 Sharing memory

6.2.1 Sharing IPC primitives between containers

  1. docker container run -d -u nobody --name ch6_ipc_producer \
  2. --ipc shareable \
  3. dockerinaction/ch6_ipc -producer
  4. docker container run -d -u nobody --name ch6_ipc_consumer \
  5. dockerinaction/ch6_ipc -consumer
  1. docker container rm -v ch6_ipc_consumer
  2. docker container run -d --name ch6_ipc_consumer \
  3. --ipc container:ch6_ipc_producer \
  4. dockerinaction/ch6_ipc -consumer
  5. docker logs ch6_ipc_producer
  6. docker logs ch6_ipc_consumer

6.3 Understanding users

6.3.1 Working with the run-as user

  1. docker image pull busybox:1.29
  2. docker image inspect busybox:1.29
  3. docker inspect --format "{{.Config.User}}" busybox:1.29

6.3.2 Users and volumes

6.3.3 Introduction to the Linux user namespace and UID remapping

6.4 Adjusting OS feature access with capabilities

6.5 Running a container with full privileges

6.6 Strengthening containers with enhanced tools

6.6.1 Specifying additional security options

6.7 Building use-case-appropriate containers