ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
Linux containers/Docker
(and how it works)
Dmitry Fedorov
Wont talk about
(Lots of talks about it allready)
This talk will not include:
Marketing stories
Docker is awesome...blah,blah,blah
Will talk about
Namespaces
Capabilities
Cgroups
Docker internals (libcontainer)
Namespaces
Namespaces
He'sback.Andthistimehe'sgotachainsaw.
Yes,folks.Wegotper-processnamespaces.Working.Withproper
behaviouronexit(),yodda,yodda.Enjoy.
Mount (Mount points)
UTS (Hostname and NIS domain name)
IPC (System V IPC, POSIX message queues)
PID (Process IDs)
Network (Network devices, stacks, ports, etc.)
User (User and group IDs)
Namespaces Api
/proc/[pid]/ns
ipc->ipc:[4026531839]
mnt->mnt:[4026531840]
net->net:[4026531956]
pid->pid:[4026531836]
user->user:[4026531837]
uts->uts:[4026531838]
Syscalls:
clone(2)
setns(2)
unshare(2)
Mount namespaces (CLONE_NEWNS)
Mount namespaces
Mount points
/proc/[pid]/mounts
/proc/[pid]/mountstats
Mount namespaces
On hostnode:
cat/proc/1/mounts|wc-l
32
Inside container:
dockerrun-it--rmcentos:centos7cat/proc/1/mounts|wc-l
16
UTS namespaces (CLONE_NEWUTS)
UTS namespaces
hostname, domainname
On hostnode:
uname-n
dfedorov
Inside container:
dockerrun-it--rmcentos:centos7sh-c'uname-n'
b543e1bb6eef
IPC namespaces (CLONE_NEWIPC)
IPC namespaces
System V IPC objects, POSIX message queues
/proc/sys/fs/mqueue
/proc/sys/kernel
/proc/sysvipc
On hostnode:
dfedorov@dfedorov:~$ipcs|wc-l
45
Inside container:
dfedorov@dfedorov:~$dockerrun-it--rmcentos:centos7ipcs|wc-l
10
PID namespaces (CLONE_NEWPID)
PID namespaces
process ID number space
Nesting namespace:
PIDnamespacescanbenested:eachPIDnamespacehasaparent,
exceptfortheinitial("root")PIDnamespace.
On hostnode:
psaux|wc-l
298
Inside container:
dockerrun-it--rmcentos:centos7psaxu|wc-l
2
Network namespaces (CLONE_NEWNET)
Network namespaces
network devices, IPv4 and IPv6 protocol stacks, IP routing tables, firewalls
/proc/net
/sys/class/net
/sys/class/net on hostnode:
docker0 eth0 lo lxcbr0 veth1 veth50cf98d veth6b9c9cc
Inside container:
docker run -it --rm centos:centos7 ls /sys/class/net
eth0 lo
Network namespaces
Create netns manualy:
ipnetnsaddminimal#Createnamespace
iplinkaddeth1typevethpeernameveth1#Createvirtualethernetdevice
iplinkseteth1netnsminimal#Attachdevicetonamespace
ipaadd10.0.0.1/24devveth1
iplsetveth1up
User namespaces (CLONE_NEWUSER)
User namespaces
user credentials (user IDs and group IDs), capabilities
Still strict user mapping. Sad ...
UID1000insidecontainer->1000onhostnode
UID0 insidecontainer->0 onhostnode
etc
And dont really work ...
sudols-l/proc/1/ns/user
lrwxrwxrwx1rootroot0Nov2814:17/proc/1/ns/user->user:[4026531837]
dockerrun-it--rmcentos:centos7ls-l/proc/1/ns/user
lrwxrwxrwx1rootroot0Nov2811:18/proc/1/ns/user->user:[4026531837]
User namespaces - Capabilities
per-thread attribute
Used caplist:
CHOWN
DAC_OVERRIDE
FOWNER
MKNOD
NET_RAW
SETGID
SETUID
SETFCAP
SETPCAP
NET_BIND_SERVICE
SYS_CHROOT
KILL
troublesome: mount (cap_sys_admin)
Cgroups
Cgroups
memory
cpu/cpuset/cpuacct
blkio
device
Purpose:
limits
accounting
afinity
permissions
Efficiency
Efficiency
isolated, but still on hostnode
cpu: native
memory: allmost native, few % shaved for accounting
network: small overhead
dics: native on volumes. overhead on layered fs
Still not a cake
What do we need on top of all of it?
unionfs (aufs, vfs)
snapshotting fs (btrfs, zfs)
CoW (thin provisioning, lvm)
Docker
Docker
container control operations
version control system
system administration
Docker Approach
Application level isolation vs OS level isolation.
One task per container.
Deduplication.
Commoditize.
Typical workflow
developer:
-- write some code
-- unit test
-- commit
docker build:
-- environment test (serverspec, rspec etc)
-- functional test
-- push to registry
devops:
-- pull images and run
Old-new challenges
Monitoring.
Logging.
Backups.
Configuration management.
No ssh, and you dont need it.
No ssh, but you have exec.
Thank you. Questions?

More Related Content

Linux containers_Docker