35
Understand how Docker works @果壳 2015.10.28 1

Understand how docker works

Embed Size (px)

Citation preview

Page 1: Understand how docker works

Understand how Docker works

⼩小拿@果壳 2015.10.28

1

Page 2: Understand how docker works

Outline• Virtualization

• Hypervisor

• chroot, namespaces, cgroups, AuFS

• LXC

• Container

• Docker

Page 3: Understand how docker works

Virtualization

Virtualization is a proven software technology that makes it possible to run multiple operating systems

and applications on the same server at the same time.

Page 4: Understand how docker works

Features

• transform hardware to software

• run multiple operating systems as virtual machines

Page 5: Understand how docker works

Intuitive Idea

Page 6: Understand how docker works

Hypervisor (VMM)

a “meta” operating system in a virtualized environment

Page 7: Understand how docker works

Types of Hypervisors

• native or bare-metal hypervisors

• hosted hypervisors

Page 8: Understand how docker works

Bare-Metal Hypervisor

Page 9: Understand how docker works

Hosted Hypervisor

Page 10: Understand how docker works

Space-Time Analysis

• heavy

• slow

Page 11: Understand how docker works

docker is a lightweight

Page 12: Understand how docker works
Page 13: Understand how docker works

(giant 1) chroot

A chroot on Unix operating systems is an operation that changes the apparent root directory for the

current running process and its children.

chroot jail

Page 14: Understand how docker works

root directory

Page 15: Understand how docker works

two Linux process resource management solutions

• namespaces (what you have)

• cgroups (what you can do)

Page 16: Understand how docker works

(giant 2) Linux Namespace

• A lightweight process virtualization

• Isolation: Enable a process to have different views of the system than other processes.

Page 17: Understand how docker works

Features• PID namespace provides isolation for the allocation of process identifiers

(PIDs), lists of processes and their details. While the new namespace is isolated from other siblings, processes in its "parent" namespace still see all processes in child namespaces—albeit with different PID numbers.

• Network namespace isolates the network interface controllers (physical or virtual), iptables firewall rules, routing tables etc. Network namespaces can be connected with each other using the "veth" virtual Ethernet device.

• UTS namespace allows changing the hostname.

• Mount namespace allows creating a different file system layout, or making certain mount points read-only.

• IPC namespace isolates the System V inter-process communication between namespaces.

• User namespace isolates the user IDs between namespaces.

Page 18: Understand how docker works

Operations• CLONE_NEWIPC

• CLONE_NEWNET

• CLONE_NEWNS

• CLONE_NEWPID

• CLONE_NEWUSER

• CLONE_NEWUTS

Page 19: Understand how docker works

Example (PID) from coolshell

Page 20: Understand how docker works

Example (PID)

Page 21: Understand how docker works

(giant 3) cgroups

cgroups is a Linux kernel feature that limits, accounts for, and isolates the resource usage (CPU, memory, disk I/O, network, etc.) of a collection of processes.

Page 22: Understand how docker works

Features• Resource limitation: groups can be set to not exceed a

configured memory limit, which also includes the file system cache

• Prioritization: some groups may get a larger share of CPU utilization[8] or disk I/O throughput

• Accounting: measures how much resources certain systems use, which may be used, for example, for billing purposes

• Control: freezing the groups of processes, their checkpointing and restarting

Page 23: Understand how docker works

Operations

Page 24: Understand how docker works

Example (CPU) from coolshell

Page 25: Understand how docker works

LXC

LinuX Container = namespaces + cgroups

Page 26: Understand how docker works

(giant 4) AuFS

AuFS (Advanced multi layered Unification FileSystem) implements a union mount for Linux file systems.

Page 27: Understand how docker works
Page 28: Understand how docker works

“When I see a bird that walks like a duck and swims like a duck and quacks like a duck,

I call that bird a duck.”

Duck Typing

Page 29: Understand how docker works

Docker = LXC + AuFS• chroot

• namespaces

• cgroups

• aufs

• …

Page 30: Understand how docker works

Container

Page 31: Understand how docker works

Pros and Cons

Page 32: Understand how docker works

Pros and Cons

Page 33: Understand how docker works

Why must install boot2docker?

Page 34: Understand how docker works

Why only contains Linux distros?