SlideShare a Scribd company logo
1 of 55
Download to read offline
Cgroups, namespaces and beyond:
What are containers made from?
Jérôme🐳🚢📦Petazzoni
Tinkerer Extraordinaire
Who am I?
Jérôme Petazzoni (@jpetazzo)
French software engineer living in California
I have built and scaled the dotCloud PaaS
almost 5 years ago, time flies!
I talk (too much) about containers
first time was maybe in February 2013, at SCALE in L.A.
Proud member of the House of Bash
when annoyed, we replace things with tiny shell scripts
Outline
What is a container?
High level and low level overviews
The building blocks
Namespaces, cgroups, copy-on-write storage
Container runtimes
Docker, LXC, rkt, runC, systemd-nspawn
OpenVZ, Jails, Zones
Hand-crafted, artisan-pick, house-blend containers
Demos!
What is a container?
📦
High level approach: it's a lightweight VM
I can get a shell on it
through SSH or otherwise
It "feels" like a VM
own process space
own network interface
can run stuff as root
can install packages
can run services
can mess up routing, iptables …
Low level approach: it's chroot on steroids
It's not quite like a VM:
uses the host kernel
can't boot a different OS
can't have its own modules
doesn't need init as PID 1
doesn't need syslogd, cron...
It's just a bunch of processes visible on the host
machine
contrast with VMs which are opaque
How are they implemented?
Let's look in the kernel source!
Go to LXR
Look for "LXC" → zero result
Look for "container" → 1000+ results
Almost all of them are about data structures
or other unrelated concepts like “ACPI containers”
There are some references to “our” containers
but only in the documentation
How are they implemented?
Let's look in the kernel source!
Go to LXR
Look for "LXC" → zero result
Look for "container" → 1000+ results
Almost all of them are about data structures
or other unrelated concepts like “ACPI containers”
There are some references to “our” containers
but only in the documentation
??? Are containers even in the kernel ???
How are they implemented?
Let's look in the kernel source!
Go to LXR
Look for "LXC" → zero result
Look for "container" → 1000+ results
Almost all of them are about data structures
or other unrelated concepts like “ACPI containers”
There are some references to “our” containers
but only in the documentation
??? Are containers even in the kernel ???
??? Do containers even actually EXIST ???
The building blocks:
control groups
Control groups
Resource metering and limiting
memory
CPU
block I/O
network*
Device node (/dev/*) access control
Crowd control
*With cooperation from iptables/tc; more on that later
Generalities
Each subsystem (memory, CPU...) has
a hierarchy (tree)
Hierarchies are independent
the trees for e.g. memory and CPU can be different
Each process belongs to exactly 1 node in each
hierarchy
think of each hierarchy as a different dimension or axis
Each hierarchy starts with 1 node (the root)
All processes initially belong to the root of each
hierarchy*
Each node = group of processes
sharing the same resources
Example
Memory cgroup: accounting
Keeps track of pages used by each group:
file (read/write/mmap from block devices)
anonymous (stack, heap, anonymous mmap)
active (recently accessed)
inactive (candidate for eviction)
Each page is “charged” to a group
Pages can be shared across multiple groups
e.g. multiple processes reading from the same files
When pages are shared, only one group “pays” for a
page
Memory cgroup: limits
Each group can have (optional) hard and soft limits
Soft limits are not enforced
they influence reclaim under memory pressure
Hard limits will trigger a per-group OOM killer
The OOM killer can be customized (oom-notifier);
when the hard limit is exceeded:
freeze all processes in the group
notify user space (instead of going rampage)
we can kill processes, raise limits, migrate containers ...
when we're in the clear again, unfreeze the group
Limits can be set for physical, kernel, total memory
Memory cgroup: tricky details
Each time the kernel gives a page to a process,
or takes it away, it updates the counters
This adds some overhead
Unfortunately, this cannot be enabled/disabled per
process
it has to be done at boot time
When multiple groups use the same page,
only the first one is “charged”
but if it stops using it, the charge is moved to another group using it
HugeTLB cgroup
Controls the amount of huge pages usable by a
process
safe to ignore if you don’t know what huge pages are
Cpu cgroup
Keeps track of user/system CPU time
Keeps track of usage per CPU
Allows to set weights
Can't set CPU limits
OK, let's say you give N%
then the CPU throttles to a lower clock speed
now what?
same if you give a time slot
instructions? their exec speed varies wildly
¯_ツ_/¯
Cpuset cgroup
Pin groups to specific CPU(s)
Reserve CPUs for specific apps
Avoid processes bouncing between CPUs
Also relevant for NUMA systems
Provides extra dials and knobs
per zone memory pressure, process migration costs…
Blkio cgroup
Keeps track of I/Os for each group
per block device
read vs write
sync vs async
Set throttle (limits) for each group
per block device
read vs write
ops vs bytes
Set relative weights for each group
Note: most writes will go through the page cache
anyway
so classic writes will appear to be unthrottled at first
Net_cls and net_prio cgroup
Automatically set traffic class or priority,
for traffic generated by processes in the group
Only works for egress traffic
Net_cls will assign traffic to a class
class then has to be matched with tc/iptables,
otherwise traffic just flows normally
Net_prio will assign traffic to a priority
priorities are used by queuing disciplines
Devices cgroup
Controls what the group can do on device nodes
Permissions include read/write/mknod
Typical use:
allow /dev/{tty,zero,random,null} ...
deny everything else
A few interesting nodes:
/dev/net/tun (network interface manipulation)
/dev/fuse (filesystems in user space)
/dev/kvm (VMs in containers, yay inception!)
/dev/dri (GPU)
Freezer cgroup
Allows to freeze/thaw a group of processes
Similar in functionality to mass SIGSTOP/SIGCONT
Cannot be detected by the processes (unlike
STOP/CONT)
Doesn’t impede ptrace/debugging
Specific usecases
cluster batch scheduling
process migration
Subtleties
PID 1 is placed at the root of each hierarchy
New processes are placed in their parent’s groups
Groups are materialized by one (or multiple) pseudo-fs
typically mounted in /sys/fs/cgroup
Groups are created by mkdir in the pseudo-fs
To move a process:
echo $PID > /sys/fs/cgroup/.../tasks
The cgroup wars: systemd vs cgmanager vs ...
The building blocks:
namespaces
Namespaces
Provide processes with their own view of the system
Cgroups = limits how much you can use;
namespaces = limits what you can see (and therefore
use)
Multiple namespaces:
pid
net
mnt
uts
ipc
user
Each process is in one namespace of each type
Pid namespace
Processes within a PID namespace only see
processes in the same PID namespace
Each PID namespace has its own numbering
starting at 1
When PID 1 goes away, the whole namespace is killed
Those namespaces can be nested
A process ends up having multiple PIDs
one per namespace in which its nested
Net namespace: in theory
Processes within a given network namespace
get their own private network stack, including:
network interfaces (including lo)
routing tables
iptables rules
sockets (ss, netstat)
You can move a network interface from a netns to
another
ip link set dev eth0 netns PID
Net namespace: in practice
Typical use-case:
use veth pairs (two virtual interfaces acting as a cross-over cable)
eth0 in container network namespace
paired with vethXXX in host network namespace
all the vethXXX are bridged together (Docker calls the
bridge docker0)
But also: the magic of --net container
shared localhost (and more!)
Mnt namespace
Processes can have their own root fs (à la chroot)
Processes can also have “private” mounts
/tmp (scoped per user, per service...)
masking of /proc, /sys
NFS auto-mounts (why not?)
Mounts can be totally private, or shared
No easy way to pass along a mount
from a namespace to another ☹
Uts namespace
gethostname / sethostname
'nuff said!
Ipc namespace
Ipc namespace
Does anybody know about IPC?
Ipc namespace
Does anybody know about IPC?
Does anybody care about IPC?
Ipc namespace
Does anybody know about IPC?
Does anybody care about IPC?
Allows a process (or group of processes) to have own:
IPC semaphores
IPC message queues
IPC shared memory
... without risk of conflict with other instances
User namespace
Allows to map UID/GID; e.g.:
UID 0→1999 in container C1 is mapped to
UID 10000→11999 on host;
UID 0→1999 in container C2 is mapped to
UID 12000→13999 on host;
etc.
Avoids extra configuration in containers
UID 0 (root) can be squashed to a non-privileged user
Security improvement
But: devil is in the details
Namespace manipulation
Namespaces are created with the clone() system call
i.e. with extra flags when creating a new process
Namespaces are materialized by pseudo-files
/proc/<pid>/ns
When the last process of a namespace exits, it is
destroyed
but can be preserved by bind-mounting the pseudo-file
It is possible to "enter" a namespace with setns()
exposed by the nsenter wrapper in util-linux
The building blocks:
copy-on-write
Copy-on-write storage
Create a new container instantly
instead of copying its whole filesystem
Storage keeps track of what has changed
Many options available
AUFS, overlay (file level)
device mapper thinp (block level)
BTRFS, ZFS (FS level)
Considerably reduces footprint and “boot” times
See also: Deep dive into Docker storage drivers
Other details
Orthogonality
All those things can be used independently
Use a few cgroups if you just need resource isolation
Simulate a network of routers with network
namespaces
Put the debugger in a container's namespaces,
but not its cgroups (to not use its resource quotas)
Setup a network interface in an isolated environment,
then move it to another
etc.
Some missing bits
Capabilities
break down "root / non-root" into fine-grained rights
allow to keep root, but without the dangerous bits
however: CAP_SYS_ADMIN remains a big catchall
SELinux / AppArmor ...
containers that actually contain
deserve a whole talk on their own
check https://github.com/jfrazelle/bane (AppArmor profile generator)
Container runtimes
Container runtimes
using cgroups+namespaces
LXC
Set of userland tools
A container is a directory in /var/lib/lxc
Small config file + root filesystem
Early versions had no support for CoW
Early versions had no support to move images around
Requires significant amount of elbow grease
easy for sysadmins/ops, hard for devs
systemd-nspawn
From its manpage:
“For debugging, testing and building”
“Similar to chroot, but more powerful”
“Implements the Container Interface”
Seems to position itself as plumbing
Recently added support for ɹǝʞɔop images
#define INDEX_HOST "index.do" /* the URL we get the data from */ "cker.io”
#define HEADER_TOKEN "X-Do" /* the HTTP header for the auth token */ "cker-Token:”
#define HEADER_REGISTRY "X-Do" /*the HTTP header for the registry */ "cker-Endpoints:”
Docker Engine
Daemon controlled by REST(ish) API
First versions shelled out to LXC
now uses its own libcontainer runtime
Manages containers, images, builds, and more
Some people think it does too many things
rkt, runC
Back to the basics!
Focus on container execution
no API, no image management, no build, etc.
They implement different specifications:
rkt implements appc (App Container)
runC implements OCP (Open Container Project)
runC leverages Docker's libcontainer
Which one is best?
They all use the same kernel features
Performance will be exactly the same
Look at:
features
design
ecosystem
Container runtimes
using other mechanisms
OpenVZ
Also Linux
Older, but battle-tested
e.g. Travis CI gives you root in OpenVZ
Tons of neat features too
ploop (efficient block device for containers)
checkpoint/restore, live migration
venet (~more efficient veth)
Still developed and maintained
Jails / Zones
FreeBSD / Solaris
Coarser granularity than namespaces and cgroups
Strong emphasis on security
Great for hosting providers
Not so much for developers
where's the equivalent of docker run -ti ubuntu?
Note: Illumos branded zones can run Linux binaries
with Joyent Triton, you can run Linux containers on Illumos
Note: this is different from the Oracle Solaris port
the latter will run Solaris binaries, not Linux binaries
Building our own
containers
For educational purposes only!
54
Thank you!
Jérôme🐳🚢📦Petazzoni
@jpetazzo
jerome@docker.com

More Related Content

What's hot

Google Kubernetes Engine (GKE) deep dive
Google Kubernetes Engine (GKE) deep diveGoogle Kubernetes Engine (GKE) deep dive
Google Kubernetes Engine (GKE) deep diveAkash Agrawal
 
Introduction to Docker - 2017
Introduction to Docker - 2017Introduction to Docker - 2017
Introduction to Docker - 2017Docker, Inc.
 
Introduction to Kubernetes Workshop
Introduction to Kubernetes WorkshopIntroduction to Kubernetes Workshop
Introduction to Kubernetes WorkshopBob Killen
 
Continuous Lifecycle London 2018 Event Keynote
Continuous Lifecycle London 2018 Event KeynoteContinuous Lifecycle London 2018 Event Keynote
Continuous Lifecycle London 2018 Event KeynoteWeaveworks
 
Designing a complete ci cd pipeline using argo events, workflow and cd products
Designing a complete ci cd pipeline using argo events, workflow and cd productsDesigning a complete ci cd pipeline using argo events, workflow and cd products
Designing a complete ci cd pipeline using argo events, workflow and cd productsJulian Mazzitelli
 
Containers: The What, Why, and How
Containers: The What, Why, and HowContainers: The What, Why, and How
Containers: The What, Why, and HowSneha Inguva
 
Kubernetes Application Deployment with Helm - A beginner Guide!
Kubernetes Application Deployment with Helm - A beginner Guide!Kubernetes Application Deployment with Helm - A beginner Guide!
Kubernetes Application Deployment with Helm - A beginner Guide!Krishna-Kumar
 
Kubernetes extensibility
Kubernetes extensibilityKubernetes extensibility
Kubernetes extensibilityDocker, Inc.
 
Kubernetes - A Comprehensive Overview
Kubernetes - A Comprehensive OverviewKubernetes - A Comprehensive Overview
Kubernetes - A Comprehensive OverviewBob Killen
 
Docker, Linux Containers (LXC), and security
Docker, Linux Containers (LXC), and securityDocker, Linux Containers (LXC), and security
Docker, Linux Containers (LXC), and securityJérôme Petazzoni
 
GitOps is the best modern practice for CD with Kubernetes
GitOps is the best modern practice for CD with KubernetesGitOps is the best modern practice for CD with Kubernetes
GitOps is the best modern practice for CD with KubernetesVolodymyr Shynkar
 
Namespaces and cgroups - the basis of Linux containers
Namespaces and cgroups - the basis of Linux containersNamespaces and cgroups - the basis of Linux containers
Namespaces and cgroups - the basis of Linux containersKernel TLV
 
Extending kubernetes with CustomResourceDefinitions
Extending kubernetes with CustomResourceDefinitionsExtending kubernetes with CustomResourceDefinitions
Extending kubernetes with CustomResourceDefinitionsStefan Schimanski
 
Kubernetes #2 monitoring
Kubernetes #2   monitoring Kubernetes #2   monitoring
Kubernetes #2 monitoring Terry Cho
 
Cgroups, namespaces, and beyond: what are containers made from? (DockerCon Eu...
Cgroups, namespaces, and beyond: what are containers made from? (DockerCon Eu...Cgroups, namespaces, and beyond: what are containers made from? (DockerCon Eu...
Cgroups, namespaces, and beyond: what are containers made from? (DockerCon Eu...Jérôme Petazzoni
 
Kubernetes Architecture and Introduction
Kubernetes Architecture and IntroductionKubernetes Architecture and Introduction
Kubernetes Architecture and IntroductionStefan Schimanski
 
OpenShift Virtualization - VM and OS Image Lifecycle
OpenShift Virtualization - VM and OS Image LifecycleOpenShift Virtualization - VM and OS Image Lifecycle
OpenShift Virtualization - VM and OS Image LifecycleMihai Criveti
 
Kvm and libvirt
Kvm and libvirtKvm and libvirt
Kvm and libvirtplarsen67
 

What's hot (20)

Google Kubernetes Engine (GKE) deep dive
Google Kubernetes Engine (GKE) deep diveGoogle Kubernetes Engine (GKE) deep dive
Google Kubernetes Engine (GKE) deep dive
 
Helm intro
Helm introHelm intro
Helm intro
 
Introduction to Docker - 2017
Introduction to Docker - 2017Introduction to Docker - 2017
Introduction to Docker - 2017
 
Kubernetes 101
Kubernetes 101Kubernetes 101
Kubernetes 101
 
Introduction to Kubernetes Workshop
Introduction to Kubernetes WorkshopIntroduction to Kubernetes Workshop
Introduction to Kubernetes Workshop
 
Continuous Lifecycle London 2018 Event Keynote
Continuous Lifecycle London 2018 Event KeynoteContinuous Lifecycle London 2018 Event Keynote
Continuous Lifecycle London 2018 Event Keynote
 
Designing a complete ci cd pipeline using argo events, workflow and cd products
Designing a complete ci cd pipeline using argo events, workflow and cd productsDesigning a complete ci cd pipeline using argo events, workflow and cd products
Designing a complete ci cd pipeline using argo events, workflow and cd products
 
Containers: The What, Why, and How
Containers: The What, Why, and HowContainers: The What, Why, and How
Containers: The What, Why, and How
 
Kubernetes Application Deployment with Helm - A beginner Guide!
Kubernetes Application Deployment with Helm - A beginner Guide!Kubernetes Application Deployment with Helm - A beginner Guide!
Kubernetes Application Deployment with Helm - A beginner Guide!
 
Kubernetes extensibility
Kubernetes extensibilityKubernetes extensibility
Kubernetes extensibility
 
Kubernetes - A Comprehensive Overview
Kubernetes - A Comprehensive OverviewKubernetes - A Comprehensive Overview
Kubernetes - A Comprehensive Overview
 
Docker, Linux Containers (LXC), and security
Docker, Linux Containers (LXC), and securityDocker, Linux Containers (LXC), and security
Docker, Linux Containers (LXC), and security
 
GitOps is the best modern practice for CD with Kubernetes
GitOps is the best modern practice for CD with KubernetesGitOps is the best modern practice for CD with Kubernetes
GitOps is the best modern practice for CD with Kubernetes
 
Namespaces and cgroups - the basis of Linux containers
Namespaces and cgroups - the basis of Linux containersNamespaces and cgroups - the basis of Linux containers
Namespaces and cgroups - the basis of Linux containers
 
Extending kubernetes with CustomResourceDefinitions
Extending kubernetes with CustomResourceDefinitionsExtending kubernetes with CustomResourceDefinitions
Extending kubernetes with CustomResourceDefinitions
 
Kubernetes #2 monitoring
Kubernetes #2   monitoring Kubernetes #2   monitoring
Kubernetes #2 monitoring
 
Cgroups, namespaces, and beyond: what are containers made from? (DockerCon Eu...
Cgroups, namespaces, and beyond: what are containers made from? (DockerCon Eu...Cgroups, namespaces, and beyond: what are containers made from? (DockerCon Eu...
Cgroups, namespaces, and beyond: what are containers made from? (DockerCon Eu...
 
Kubernetes Architecture and Introduction
Kubernetes Architecture and IntroductionKubernetes Architecture and Introduction
Kubernetes Architecture and Introduction
 
OpenShift Virtualization - VM and OS Image Lifecycle
OpenShift Virtualization - VM and OS Image LifecycleOpenShift Virtualization - VM and OS Image Lifecycle
OpenShift Virtualization - VM and OS Image Lifecycle
 
Kvm and libvirt
Kvm and libvirtKvm and libvirt
Kvm and libvirt
 

Similar to Cgroups, namespaces and beyond: what are containers made from?

LXC Containers and AUFs
LXC Containers and AUFsLXC Containers and AUFs
LXC Containers and AUFsDocker, Inc.
 
Scale11x lxc talk
Scale11x lxc talkScale11x lxc talk
Scale11x lxc talkdotCloud
 
Lightweight Virtualization: LXC containers & AUFS
Lightweight Virtualization: LXC containers & AUFSLightweight Virtualization: LXC containers & AUFS
Lightweight Virtualization: LXC containers & AUFSJérôme Petazzoni
 
Containerization is more than the new Virtualization: enabling separation of ...
Containerization is more than the new Virtualization: enabling separation of ...Containerization is more than the new Virtualization: enabling separation of ...
Containerization is more than the new Virtualization: enabling separation of ...Jérôme Petazzoni
 
Containerization Is More than the New Virtualization
Containerization Is More than the New VirtualizationContainerization Is More than the New Virtualization
Containerization Is More than the New VirtualizationC4Media
 
Introduction to containers
Introduction to containersIntroduction to containers
Introduction to containersNitish Jadia
 
Linux 开源操作系统发展新趋势
Linux 开源操作系统发展新趋势Linux 开源操作系统发展新趋势
Linux 开源操作系统发展新趋势Anthony Wong
 
The building blocks of docker.
The building blocks of docker.The building blocks of docker.
The building blocks of docker.Chafik Belhaoues
 
Realizing Linux Containers (LXC)
Realizing Linux Containers (LXC)Realizing Linux Containers (LXC)
Realizing Linux Containers (LXC)Boden Russell
 
Operating System 4 1193308760782240 2
Operating System 4 1193308760782240 2Operating System 4 1193308760782240 2
Operating System 4 1193308760782240 2mona_hakmy
 
Operating System 4
Operating System 4Operating System 4
Operating System 4tech2click
 
Let's Containerize New York with Docker!
Let's Containerize New York with Docker!Let's Containerize New York with Docker!
Let's Containerize New York with Docker!Jérôme Petazzoni
 
Advanced Namespaces and cgroups
Advanced Namespaces and cgroupsAdvanced Namespaces and cgroups
Advanced Namespaces and cgroupsKernel TLV
 
Introduction to OS LEVEL Virtualization & Containers
Introduction to OS LEVEL Virtualization & ContainersIntroduction to OS LEVEL Virtualization & Containers
Introduction to OS LEVEL Virtualization & ContainersVaibhav Sharma
 
Lightweight Virtualization in Linux
Lightweight Virtualization in LinuxLightweight Virtualization in Linux
Lightweight Virtualization in LinuxSadegh Dorri N.
 
Linux container, namespaces & CGroup.
Linux container, namespaces & CGroup. Linux container, namespaces & CGroup.
Linux container, namespaces & CGroup. Neeraj Shrimali
 
Docker Tips And Tricks at the Docker Beijing Meetup
Docker Tips And Tricks at the Docker Beijing MeetupDocker Tips And Tricks at the Docker Beijing Meetup
Docker Tips And Tricks at the Docker Beijing MeetupJérôme Petazzoni
 
Docker, Linux Containers, and Security: Does It Add Up?
Docker, Linux Containers, and Security: Does It Add Up?Docker, Linux Containers, and Security: Does It Add Up?
Docker, Linux Containers, and Security: Does It Add Up?Jérôme Petazzoni
 

Similar to Cgroups, namespaces and beyond: what are containers made from? (20)

LXC Containers and AUFs
LXC Containers and AUFsLXC Containers and AUFs
LXC Containers and AUFs
 
Scale11x lxc talk
Scale11x lxc talkScale11x lxc talk
Scale11x lxc talk
 
Lightweight Virtualization: LXC containers & AUFS
Lightweight Virtualization: LXC containers & AUFSLightweight Virtualization: LXC containers & AUFS
Lightweight Virtualization: LXC containers & AUFS
 
Containerization is more than the new Virtualization: enabling separation of ...
Containerization is more than the new Virtualization: enabling separation of ...Containerization is more than the new Virtualization: enabling separation of ...
Containerization is more than the new Virtualization: enabling separation of ...
 
.ppt
.ppt.ppt
.ppt
 
Containerization Is More than the New Virtualization
Containerization Is More than the New VirtualizationContainerization Is More than the New Virtualization
Containerization Is More than the New Virtualization
 
Introduction to containers
Introduction to containersIntroduction to containers
Introduction to containers
 
Linux 开源操作系统发展新趋势
Linux 开源操作系统发展新趋势Linux 开源操作系统发展新趋势
Linux 开源操作系统发展新趋势
 
The building blocks of docker.
The building blocks of docker.The building blocks of docker.
The building blocks of docker.
 
Realizing Linux Containers (LXC)
Realizing Linux Containers (LXC)Realizing Linux Containers (LXC)
Realizing Linux Containers (LXC)
 
Operating System 4 1193308760782240 2
Operating System 4 1193308760782240 2Operating System 4 1193308760782240 2
Operating System 4 1193308760782240 2
 
Operating System 4
Operating System 4Operating System 4
Operating System 4
 
Let's Containerize New York with Docker!
Let's Containerize New York with Docker!Let's Containerize New York with Docker!
Let's Containerize New York with Docker!
 
Advanced Namespaces and cgroups
Advanced Namespaces and cgroupsAdvanced Namespaces and cgroups
Advanced Namespaces and cgroups
 
Introduction to OS LEVEL Virtualization & Containers
Introduction to OS LEVEL Virtualization & ContainersIntroduction to OS LEVEL Virtualization & Containers
Introduction to OS LEVEL Virtualization & Containers
 
Lightweight Virtualization in Linux
Lightweight Virtualization in LinuxLightweight Virtualization in Linux
Lightweight Virtualization in Linux
 
Linux container, namespaces & CGroup.
Linux container, namespaces & CGroup. Linux container, namespaces & CGroup.
Linux container, namespaces & CGroup.
 
Kubernetes: My BFF
Kubernetes: My BFFKubernetes: My BFF
Kubernetes: My BFF
 
Docker Tips And Tricks at the Docker Beijing Meetup
Docker Tips And Tricks at the Docker Beijing MeetupDocker Tips And Tricks at the Docker Beijing Meetup
Docker Tips And Tricks at the Docker Beijing Meetup
 
Docker, Linux Containers, and Security: Does It Add Up?
Docker, Linux Containers, and Security: Does It Add Up?Docker, Linux Containers, and Security: Does It Add Up?
Docker, Linux Containers, and Security: Does It Add Up?
 

More from Docker, Inc.

Containerize Your Game Server for the Best Multiplayer Experience
Containerize Your Game Server for the Best Multiplayer Experience Containerize Your Game Server for the Best Multiplayer Experience
Containerize Your Game Server for the Best Multiplayer Experience Docker, Inc.
 
How to Improve Your Image Builds Using Advance Docker Build
How to Improve Your Image Builds Using Advance Docker BuildHow to Improve Your Image Builds Using Advance Docker Build
How to Improve Your Image Builds Using Advance Docker BuildDocker, Inc.
 
Build & Deploy Multi-Container Applications to AWS
Build & Deploy Multi-Container Applications to AWSBuild & Deploy Multi-Container Applications to AWS
Build & Deploy Multi-Container Applications to AWSDocker, Inc.
 
Securing Your Containerized Applications with NGINX
Securing Your Containerized Applications with NGINXSecuring Your Containerized Applications with NGINX
Securing Your Containerized Applications with NGINXDocker, Inc.
 
How To Build and Run Node Apps with Docker and Compose
How To Build and Run Node Apps with Docker and ComposeHow To Build and Run Node Apps with Docker and Compose
How To Build and Run Node Apps with Docker and ComposeDocker, Inc.
 
Distributed Deep Learning with Docker at Salesforce
Distributed Deep Learning with Docker at SalesforceDistributed Deep Learning with Docker at Salesforce
Distributed Deep Learning with Docker at SalesforceDocker, Inc.
 
The First 10M Pulls: Building The Official Curl Image for Docker Hub
The First 10M Pulls: Building The Official Curl Image for Docker HubThe First 10M Pulls: Building The Official Curl Image for Docker Hub
The First 10M Pulls: Building The Official Curl Image for Docker HubDocker, Inc.
 
Monitoring in a Microservices World
Monitoring in a Microservices WorldMonitoring in a Microservices World
Monitoring in a Microservices WorldDocker, Inc.
 
COVID-19 in Italy: How Docker is Helping the Biggest Italian IT Company Conti...
COVID-19 in Italy: How Docker is Helping the Biggest Italian IT Company Conti...COVID-19 in Italy: How Docker is Helping the Biggest Italian IT Company Conti...
COVID-19 in Italy: How Docker is Helping the Biggest Italian IT Company Conti...Docker, Inc.
 
Predicting Space Weather with Docker
Predicting Space Weather with DockerPredicting Space Weather with Docker
Predicting Space Weather with DockerDocker, Inc.
 
Become a Docker Power User With Microsoft Visual Studio Code
Become a Docker Power User With Microsoft Visual Studio CodeBecome a Docker Power User With Microsoft Visual Studio Code
Become a Docker Power User With Microsoft Visual Studio CodeDocker, Inc.
 
How to Use Mirroring and Caching to Optimize your Container Registry
How to Use Mirroring and Caching to Optimize your Container RegistryHow to Use Mirroring and Caching to Optimize your Container Registry
How to Use Mirroring and Caching to Optimize your Container RegistryDocker, Inc.
 
Monolithic to Microservices + Docker = SDLC on Steroids!
Monolithic to Microservices + Docker = SDLC on Steroids!Monolithic to Microservices + Docker = SDLC on Steroids!
Monolithic to Microservices + Docker = SDLC on Steroids!Docker, Inc.
 
Kubernetes at Datadog Scale
Kubernetes at Datadog ScaleKubernetes at Datadog Scale
Kubernetes at Datadog ScaleDocker, Inc.
 
Labels, Labels, Labels
Labels, Labels, Labels Labels, Labels, Labels
Labels, Labels, Labels Docker, Inc.
 
Using Docker Hub at Scale to Support Micro Focus' Delivery and Deployment Model
Using Docker Hub at Scale to Support Micro Focus' Delivery and Deployment ModelUsing Docker Hub at Scale to Support Micro Focus' Delivery and Deployment Model
Using Docker Hub at Scale to Support Micro Focus' Delivery and Deployment ModelDocker, Inc.
 
Build & Deploy Multi-Container Applications to AWS
Build & Deploy Multi-Container Applications to AWSBuild & Deploy Multi-Container Applications to AWS
Build & Deploy Multi-Container Applications to AWSDocker, Inc.
 
From Fortran on the Desktop to Kubernetes in the Cloud: A Windows Migration S...
From Fortran on the Desktop to Kubernetes in the Cloud: A Windows Migration S...From Fortran on the Desktop to Kubernetes in the Cloud: A Windows Migration S...
From Fortran on the Desktop to Kubernetes in the Cloud: A Windows Migration S...Docker, Inc.
 
Developing with Docker for the Arm Architecture
Developing with Docker for the Arm ArchitectureDeveloping with Docker for the Arm Architecture
Developing with Docker for the Arm ArchitectureDocker, Inc.
 

More from Docker, Inc. (20)

Containerize Your Game Server for the Best Multiplayer Experience
Containerize Your Game Server for the Best Multiplayer Experience Containerize Your Game Server for the Best Multiplayer Experience
Containerize Your Game Server for the Best Multiplayer Experience
 
How to Improve Your Image Builds Using Advance Docker Build
How to Improve Your Image Builds Using Advance Docker BuildHow to Improve Your Image Builds Using Advance Docker Build
How to Improve Your Image Builds Using Advance Docker Build
 
Build & Deploy Multi-Container Applications to AWS
Build & Deploy Multi-Container Applications to AWSBuild & Deploy Multi-Container Applications to AWS
Build & Deploy Multi-Container Applications to AWS
 
Securing Your Containerized Applications with NGINX
Securing Your Containerized Applications with NGINXSecuring Your Containerized Applications with NGINX
Securing Your Containerized Applications with NGINX
 
How To Build and Run Node Apps with Docker and Compose
How To Build and Run Node Apps with Docker and ComposeHow To Build and Run Node Apps with Docker and Compose
How To Build and Run Node Apps with Docker and Compose
 
Hands-on Helm
Hands-on Helm Hands-on Helm
Hands-on Helm
 
Distributed Deep Learning with Docker at Salesforce
Distributed Deep Learning with Docker at SalesforceDistributed Deep Learning with Docker at Salesforce
Distributed Deep Learning with Docker at Salesforce
 
The First 10M Pulls: Building The Official Curl Image for Docker Hub
The First 10M Pulls: Building The Official Curl Image for Docker HubThe First 10M Pulls: Building The Official Curl Image for Docker Hub
The First 10M Pulls: Building The Official Curl Image for Docker Hub
 
Monitoring in a Microservices World
Monitoring in a Microservices WorldMonitoring in a Microservices World
Monitoring in a Microservices World
 
COVID-19 in Italy: How Docker is Helping the Biggest Italian IT Company Conti...
COVID-19 in Italy: How Docker is Helping the Biggest Italian IT Company Conti...COVID-19 in Italy: How Docker is Helping the Biggest Italian IT Company Conti...
COVID-19 in Italy: How Docker is Helping the Biggest Italian IT Company Conti...
 
Predicting Space Weather with Docker
Predicting Space Weather with DockerPredicting Space Weather with Docker
Predicting Space Weather with Docker
 
Become a Docker Power User With Microsoft Visual Studio Code
Become a Docker Power User With Microsoft Visual Studio CodeBecome a Docker Power User With Microsoft Visual Studio Code
Become a Docker Power User With Microsoft Visual Studio Code
 
How to Use Mirroring and Caching to Optimize your Container Registry
How to Use Mirroring and Caching to Optimize your Container RegistryHow to Use Mirroring and Caching to Optimize your Container Registry
How to Use Mirroring and Caching to Optimize your Container Registry
 
Monolithic to Microservices + Docker = SDLC on Steroids!
Monolithic to Microservices + Docker = SDLC on Steroids!Monolithic to Microservices + Docker = SDLC on Steroids!
Monolithic to Microservices + Docker = SDLC on Steroids!
 
Kubernetes at Datadog Scale
Kubernetes at Datadog ScaleKubernetes at Datadog Scale
Kubernetes at Datadog Scale
 
Labels, Labels, Labels
Labels, Labels, Labels Labels, Labels, Labels
Labels, Labels, Labels
 
Using Docker Hub at Scale to Support Micro Focus' Delivery and Deployment Model
Using Docker Hub at Scale to Support Micro Focus' Delivery and Deployment ModelUsing Docker Hub at Scale to Support Micro Focus' Delivery and Deployment Model
Using Docker Hub at Scale to Support Micro Focus' Delivery and Deployment Model
 
Build & Deploy Multi-Container Applications to AWS
Build & Deploy Multi-Container Applications to AWSBuild & Deploy Multi-Container Applications to AWS
Build & Deploy Multi-Container Applications to AWS
 
From Fortran on the Desktop to Kubernetes in the Cloud: A Windows Migration S...
From Fortran on the Desktop to Kubernetes in the Cloud: A Windows Migration S...From Fortran on the Desktop to Kubernetes in the Cloud: A Windows Migration S...
From Fortran on the Desktop to Kubernetes in the Cloud: A Windows Migration S...
 
Developing with Docker for the Arm Architecture
Developing with Docker for the Arm ArchitectureDeveloping with Docker for the Arm Architecture
Developing with Docker for the Arm Architecture
 

Recently uploaded

Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...BookNet Canada
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Nikki Chapple
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integrationmarketing932765
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxfnnc6jmgwh
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Jeffrey Haguewood
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
A Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxA Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxAna-Maria Mihalceanu
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...itnewsafrica
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Kaya Weers
 

Recently uploaded (20)

Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
A Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxA Glance At The Java Performance Toolbox
A Glance At The Java Performance Toolbox
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)
 

Cgroups, namespaces and beyond: what are containers made from?

  • 1. Cgroups, namespaces and beyond: What are containers made from? Jérôme🐳🚢📦Petazzoni Tinkerer Extraordinaire
  • 2. Who am I? Jérôme Petazzoni (@jpetazzo) French software engineer living in California I have built and scaled the dotCloud PaaS almost 5 years ago, time flies! I talk (too much) about containers first time was maybe in February 2013, at SCALE in L.A. Proud member of the House of Bash when annoyed, we replace things with tiny shell scripts
  • 3. Outline What is a container? High level and low level overviews The building blocks Namespaces, cgroups, copy-on-write storage Container runtimes Docker, LXC, rkt, runC, systemd-nspawn OpenVZ, Jails, Zones Hand-crafted, artisan-pick, house-blend containers Demos!
  • 4. What is a container? 📦
  • 5. High level approach: it's a lightweight VM I can get a shell on it through SSH or otherwise It "feels" like a VM own process space own network interface can run stuff as root can install packages can run services can mess up routing, iptables …
  • 6. Low level approach: it's chroot on steroids It's not quite like a VM: uses the host kernel can't boot a different OS can't have its own modules doesn't need init as PID 1 doesn't need syslogd, cron... It's just a bunch of processes visible on the host machine contrast with VMs which are opaque
  • 7. How are they implemented? Let's look in the kernel source! Go to LXR Look for "LXC" → zero result Look for "container" → 1000+ results Almost all of them are about data structures or other unrelated concepts like “ACPI containers” There are some references to “our” containers but only in the documentation
  • 8. How are they implemented? Let's look in the kernel source! Go to LXR Look for "LXC" → zero result Look for "container" → 1000+ results Almost all of them are about data structures or other unrelated concepts like “ACPI containers” There are some references to “our” containers but only in the documentation ??? Are containers even in the kernel ???
  • 9. How are they implemented? Let's look in the kernel source! Go to LXR Look for "LXC" → zero result Look for "container" → 1000+ results Almost all of them are about data structures or other unrelated concepts like “ACPI containers” There are some references to “our” containers but only in the documentation ??? Are containers even in the kernel ??? ??? Do containers even actually EXIST ???
  • 11. Control groups Resource metering and limiting memory CPU block I/O network* Device node (/dev/*) access control Crowd control *With cooperation from iptables/tc; more on that later
  • 12. Generalities Each subsystem (memory, CPU...) has a hierarchy (tree) Hierarchies are independent the trees for e.g. memory and CPU can be different Each process belongs to exactly 1 node in each hierarchy think of each hierarchy as a different dimension or axis Each hierarchy starts with 1 node (the root) All processes initially belong to the root of each hierarchy* Each node = group of processes sharing the same resources
  • 14. Memory cgroup: accounting Keeps track of pages used by each group: file (read/write/mmap from block devices) anonymous (stack, heap, anonymous mmap) active (recently accessed) inactive (candidate for eviction) Each page is “charged” to a group Pages can be shared across multiple groups e.g. multiple processes reading from the same files When pages are shared, only one group “pays” for a page
  • 15. Memory cgroup: limits Each group can have (optional) hard and soft limits Soft limits are not enforced they influence reclaim under memory pressure Hard limits will trigger a per-group OOM killer The OOM killer can be customized (oom-notifier); when the hard limit is exceeded: freeze all processes in the group notify user space (instead of going rampage) we can kill processes, raise limits, migrate containers ... when we're in the clear again, unfreeze the group Limits can be set for physical, kernel, total memory
  • 16. Memory cgroup: tricky details Each time the kernel gives a page to a process, or takes it away, it updates the counters This adds some overhead Unfortunately, this cannot be enabled/disabled per process it has to be done at boot time When multiple groups use the same page, only the first one is “charged” but if it stops using it, the charge is moved to another group using it
  • 17. HugeTLB cgroup Controls the amount of huge pages usable by a process safe to ignore if you don’t know what huge pages are
  • 18. Cpu cgroup Keeps track of user/system CPU time Keeps track of usage per CPU Allows to set weights Can't set CPU limits OK, let's say you give N% then the CPU throttles to a lower clock speed now what? same if you give a time slot instructions? their exec speed varies wildly ¯_ツ_/¯
  • 19. Cpuset cgroup Pin groups to specific CPU(s) Reserve CPUs for specific apps Avoid processes bouncing between CPUs Also relevant for NUMA systems Provides extra dials and knobs per zone memory pressure, process migration costs…
  • 20. Blkio cgroup Keeps track of I/Os for each group per block device read vs write sync vs async Set throttle (limits) for each group per block device read vs write ops vs bytes Set relative weights for each group Note: most writes will go through the page cache anyway so classic writes will appear to be unthrottled at first
  • 21. Net_cls and net_prio cgroup Automatically set traffic class or priority, for traffic generated by processes in the group Only works for egress traffic Net_cls will assign traffic to a class class then has to be matched with tc/iptables, otherwise traffic just flows normally Net_prio will assign traffic to a priority priorities are used by queuing disciplines
  • 22. Devices cgroup Controls what the group can do on device nodes Permissions include read/write/mknod Typical use: allow /dev/{tty,zero,random,null} ... deny everything else A few interesting nodes: /dev/net/tun (network interface manipulation) /dev/fuse (filesystems in user space) /dev/kvm (VMs in containers, yay inception!) /dev/dri (GPU)
  • 23. Freezer cgroup Allows to freeze/thaw a group of processes Similar in functionality to mass SIGSTOP/SIGCONT Cannot be detected by the processes (unlike STOP/CONT) Doesn’t impede ptrace/debugging Specific usecases cluster batch scheduling process migration
  • 24. Subtleties PID 1 is placed at the root of each hierarchy New processes are placed in their parent’s groups Groups are materialized by one (or multiple) pseudo-fs typically mounted in /sys/fs/cgroup Groups are created by mkdir in the pseudo-fs To move a process: echo $PID > /sys/fs/cgroup/.../tasks The cgroup wars: systemd vs cgmanager vs ...
  • 26. Namespaces Provide processes with their own view of the system Cgroups = limits how much you can use; namespaces = limits what you can see (and therefore use) Multiple namespaces: pid net mnt uts ipc user Each process is in one namespace of each type
  • 27. Pid namespace Processes within a PID namespace only see processes in the same PID namespace Each PID namespace has its own numbering starting at 1 When PID 1 goes away, the whole namespace is killed Those namespaces can be nested A process ends up having multiple PIDs one per namespace in which its nested
  • 28. Net namespace: in theory Processes within a given network namespace get their own private network stack, including: network interfaces (including lo) routing tables iptables rules sockets (ss, netstat) You can move a network interface from a netns to another ip link set dev eth0 netns PID
  • 29. Net namespace: in practice Typical use-case: use veth pairs (two virtual interfaces acting as a cross-over cable) eth0 in container network namespace paired with vethXXX in host network namespace all the vethXXX are bridged together (Docker calls the bridge docker0) But also: the magic of --net container shared localhost (and more!)
  • 30. Mnt namespace Processes can have their own root fs (à la chroot) Processes can also have “private” mounts /tmp (scoped per user, per service...) masking of /proc, /sys NFS auto-mounts (why not?) Mounts can be totally private, or shared No easy way to pass along a mount from a namespace to another ☹
  • 31. Uts namespace gethostname / sethostname 'nuff said!
  • 33. Ipc namespace Does anybody know about IPC?
  • 34. Ipc namespace Does anybody know about IPC? Does anybody care about IPC?
  • 35. Ipc namespace Does anybody know about IPC? Does anybody care about IPC? Allows a process (or group of processes) to have own: IPC semaphores IPC message queues IPC shared memory ... without risk of conflict with other instances
  • 36. User namespace Allows to map UID/GID; e.g.: UID 0→1999 in container C1 is mapped to UID 10000→11999 on host; UID 0→1999 in container C2 is mapped to UID 12000→13999 on host; etc. Avoids extra configuration in containers UID 0 (root) can be squashed to a non-privileged user Security improvement But: devil is in the details
  • 37. Namespace manipulation Namespaces are created with the clone() system call i.e. with extra flags when creating a new process Namespaces are materialized by pseudo-files /proc/<pid>/ns When the last process of a namespace exits, it is destroyed but can be preserved by bind-mounting the pseudo-file It is possible to "enter" a namespace with setns() exposed by the nsenter wrapper in util-linux
  • 39. Copy-on-write storage Create a new container instantly instead of copying its whole filesystem Storage keeps track of what has changed Many options available AUFS, overlay (file level) device mapper thinp (block level) BTRFS, ZFS (FS level) Considerably reduces footprint and “boot” times See also: Deep dive into Docker storage drivers
  • 41. Orthogonality All those things can be used independently Use a few cgroups if you just need resource isolation Simulate a network of routers with network namespaces Put the debugger in a container's namespaces, but not its cgroups (to not use its resource quotas) Setup a network interface in an isolated environment, then move it to another etc.
  • 42. Some missing bits Capabilities break down "root / non-root" into fine-grained rights allow to keep root, but without the dangerous bits however: CAP_SYS_ADMIN remains a big catchall SELinux / AppArmor ... containers that actually contain deserve a whole talk on their own check https://github.com/jfrazelle/bane (AppArmor profile generator)
  • 45. LXC Set of userland tools A container is a directory in /var/lib/lxc Small config file + root filesystem Early versions had no support for CoW Early versions had no support to move images around Requires significant amount of elbow grease easy for sysadmins/ops, hard for devs
  • 46. systemd-nspawn From its manpage: “For debugging, testing and building” “Similar to chroot, but more powerful” “Implements the Container Interface” Seems to position itself as plumbing Recently added support for ɹǝʞɔop images #define INDEX_HOST "index.do" /* the URL we get the data from */ "cker.io” #define HEADER_TOKEN "X-Do" /* the HTTP header for the auth token */ "cker-Token:” #define HEADER_REGISTRY "X-Do" /*the HTTP header for the registry */ "cker-Endpoints:”
  • 47. Docker Engine Daemon controlled by REST(ish) API First versions shelled out to LXC now uses its own libcontainer runtime Manages containers, images, builds, and more Some people think it does too many things
  • 48. rkt, runC Back to the basics! Focus on container execution no API, no image management, no build, etc. They implement different specifications: rkt implements appc (App Container) runC implements OCP (Open Container Project) runC leverages Docker's libcontainer
  • 49. Which one is best? They all use the same kernel features Performance will be exactly the same Look at: features design ecosystem
  • 51. OpenVZ Also Linux Older, but battle-tested e.g. Travis CI gives you root in OpenVZ Tons of neat features too ploop (efficient block device for containers) checkpoint/restore, live migration venet (~more efficient veth) Still developed and maintained
  • 52. Jails / Zones FreeBSD / Solaris Coarser granularity than namespaces and cgroups Strong emphasis on security Great for hosting providers Not so much for developers where's the equivalent of docker run -ti ubuntu? Note: Illumos branded zones can run Linux binaries with Joyent Triton, you can run Linux containers on Illumos Note: this is different from the Oracle Solaris port the latter will run Solaris binaries, not Linux binaries