SlideShare una empresa de Scribd logo
1 de 62
Descargar para leer sin conexión
a
Gentle Introduction
to

Docker
and
All Things Containers
December 2013—updated for Docker 0.7
Outline
●

Whom is this for?

●

What's the problem?

●

What's a Container?

●

Docker 101

●

Docker images

●

Docker deployment

●

Docker future
Outline
●

Whom is this for?

●

What's the problem?

●

What's a Container?

●

Docker 101

●

Docker images

●

Docker deployment

●

Docker future
Devs
●

all languages

●

all databases

●

all O/S

●

targetting Linux systems

Docker will eventually be able to target FreeBSD, Solaris, and maybe OS X.
Ops
●

any distro

●

any cloud

●

any machine (physical, virtual...)

●

recent kernels
–

at least 3.8

–

or the one that comes with RHEL 6.5
CFO, CIO, CTO, ...
●

LESS overhead!

●

MOAR consolidation!

●

MOAR agility!

●

LESS costs!
Outline
●

Whom is this for?

●

What's the problem?

●

What's a Container?

●

Docker 101

●

Docker images

●

Docker deployment

●

Docker future
The Matrix From Hell
django
web frontend
node.js
async API
background
workers
SQL
database
distributed
DB, big data
message
queue

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

my
laptop

your
laptop

staging

prod on
cloud VM

prod on
bare metal

QA
Another Matrix from Hell
?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?
Solution:
the intermodal shipping container
Solved!
Solution to the deployment problem:

the Linux container
Linux containers...
Units of software delivery (ship it!)
●

run everywhere
–
–

regardless of host distro

–
●

regardless of kernel version
(but container and host architecture must match*)

run anything
–

if it can run on the host, it can run in the container

–

i.e., if it can run on a Linux kernel, it can run

*Unless you emulate CPU with qemu and binfmt
Outline
●

Whom is this for?

●

What's the problem?

●

What's a Container?

●

Docker 101

●

Docker images

●

Docker deployment

●

Docker future
High level approach:
it's a lightweight VM
●

own process space

●

own network interface

●

can run stuff as root

●

can have its own /sbin/init
(different from the host)

« Machine Container »
Low level approach:
it's chroot on steroids
●

can also not have its own /sbin/init

●

container = isolated process(es)

●

share kernel with host

●

no device emulation (neither HVM nor PV)

« Application Container »
Separation of concerns:
Dave the Developer
●

inside my container:
–

my code

–

my libraries

–

my package manager

–

my app

–

my data
Separation of concerns:
Oscar the Ops guy
●

outside the container:
–

logging

–

remote access

–

network configuration

–

monitoring
How does it work?
Isolation with namespaces
●

pid

●

mnt

●

net

●

uts

●

ipc

●

user
pid namespace
jpetazzo@tarrasque:~$ ps aux | wc -l
212
jpetazzo@tarrasque:~$ sudo docker run -t
bash
root@ea319b8ac416:/# ps aux
USER
PID %CPU %MEM
VSZ
RSS TTY
STAT
COMMAND
root
1 0.0 0.0 18044 1956 ?
S
root
16 0.0 0.0 15276 1136 ?
R+
aux

(That's 2 processes)

-i ubuntu
START

TIME

02:54
02:55

0:00 bash
0:00 ps
mnt namespace
jpetazzo@tarrasque:~$ wc -l
/proc/mounts
32 /proc/mounts

root@ea319b8ac416:/# wc -l
/proc/mounts
10 /proc/mounts
net namespace
root@ea319b8ac416:/# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
22: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP>
pfifo_fast state UP qlen 1000

mtu 1500 qdisc

link/ether 2a:d1:4b:7e:bf:b5 brd ff:ff:ff:ff:ff:ff
inet 10.1.1.3/24 brd 10.1.1.255 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::28d1:4bff:fe7e:bfb5/64 scope link
valid_lft forever preferred_lft forever
uts namespace
jpetazzo@tarrasque:~$ hostname
tarrasque
root@ea319b8ac416:/# hostname
ea319b8ac416
ipc namespace
jpetazzo@tarrasque:~$ ipcs
------ Shared Memory Segments -------key
shmid
owner
perms
0x00000000 3178496
jpetazzo
600
0x00000000 557057
jpetazzo
777
0x00000000 3211266
jpetazzo
600

root@ea319b8ac416:/# ipcs
------ Shared Memory Segments -------key
shmid
owner
perms
------ Semaphore Arrays -------key
semid
owner
perms
------ Message Queues -------key
msqid
owner
perms

bytes
393216
2778672
393216

nattch
2
0
2

status
dest

bytes

nattch

status

nsems
used-bytes

messages

dest
user namespace
●
●

no « demo » for this one... Yet!
UID 0→1999 in container C1 is mapped to
UID 10000→11999 in host;
UID 0→1999 in container C2 is mapped to
UID 12000→13999 in host; etc.

●

required lots of VFS and FS patches (esp. XFS)

●

what will happen with copy-on-write?
–

double translation at VFS?

–

single root UID on read-only FS?
How does it work?
Isolation with cgroups
●

memory

●

cpu

●

blkio

●

devices
How does it work?
Isolation with cgroups
●

memory

●

cpu

●

blkio

●

devices
memory cgroup
●

keeps track pages used by each group:
–

file (read/write/mmap from block devices; swap)

–

anonymous (stack, heap, anonymous mmap)

–

active (recently accessed)

–

inactive (candidate for eviction)

●

each page is « charged » to a group

●

pages can be shared (e.g. if you use any COW FS)

●

Individual (per-cgroup) limits and out-of-memory killer
cpu and cpuset cgroups
●

keep track of user/system CPU time

●

set relative weight per group

●

pin groups to specific CPU(s)
–

Can be used to « reserve » CPUs for some apps

–

This is also relevant for big NUMA systems
blkio cgroups
●

keep track IOs for each block device
–

read vs write; sync vs async

●

set relative weights

●

set throttle (limits) for each block device
–

read vs write; bytes/sec vs operations/sec

Note: earlier versions (<3.8) didn't account async correctly.
3.8 is better, but use 3.10 for best results.
devices cgroups
●

controls read/write/mknod permissions

●

typically:
–

allow: /dev/{tty,zero,random,null}...

–

deny: everything else

–

maybe: /dev/net/tun, /dev/fuse
If you're serious about security,
you also need…
●

capabilities
–

okay: cap_ipc_lock, cap_lease, cap_mknod, cap_net_admin,
cap_net_bind_service, cap_net_raw

–

troublesome: cap_sys_admin (mount!)

●

think twice before granting root

●

grsec is nice

●

seccomp (very specific use cases); seccomp-bpf

●

beware of full-scale kernel exploits!
How does it work?
Copy-on-write storage
●

●

●

unioning filesystems
(AUFS, overlayfs)
snapshotting filesystems
(BTRFS, ZFS)
copy-on-write block devices
(thin snapshots with LVM or device-mapper)

Since 0.7, Docker has a storage plugin system!
Efficiency
Compute efficiency:
almost no overhead
●

●

●

●

processes are isolated,
but run straight on the host
CPU performance
= native performance
memory performance
= a few % shaved off for (optional) accounting
network performance
= small overhead; can be reduced to zero
Storage efficiency:
many options!
Union
Filesystems

Snapshotting
Filesystems

Copy-on-write
block devices

Provisioning

Superfast
Supercheap

Fast
Cheap

Fast
Cheap

Changing
small files
Changing
large files
Diffing

Superfast
Supercheap

Fast
Cheap

Fast
Costly

Slow (first time)
Inefficient (copy-up!)

Fast
Cheap

Fast
Cheap

Superfast

Superfast (ZFS)
Kinda meh (BTRFS)

Slow

Memory usage

Efficient

Efficient

Inefficient
(at high densities)

Drawbacks

Random quirks
AUFS not mainline
!AUFS more quirks

ZFS not mainline
BTRFS not as nice

Higher disk usage
Great performance
(except diffing)

Bottom line

Ideal for PAAS and
high density things

This might be the
Future

Dodge Ram 3500
Outline
●

Whom is this for?

●

What's the problem?

●

What's a Container?

●

Docker 101

●

Docker images

●

Docker deployment

●

Docker future
Docker-what?
●

Open Source engine to commoditize LXC

●

using copy-on-write for quick provisioning

STOP!
HAMMER DEMO TIME.
Yes, but...
●

●

●

« I don't need Docker;
I can do all that stuff with LXC tools, rsync,
and some scripts! »
correct on all accounts;
but it's also true for apt, dpkg, rpm, yum, etc.
the whole point is to commoditize,
i.e. make it ridiculously easy to use
Containers before Docker
Containers after Docker
What this really means…
●

instead of writing « very small shell scripts » to
manage containers, write them to do the rest:
–

continuous deployment/integration/testing

–

orchestration

●

= use Docker as a building block

●

re-use other people images (yay ecosystem!)
Docker-what?
The Big Picture
●

Open Source engine to commoditize LXC

●

using copy-on-write for quick provisioning

●

allowing to create and share images

●

●

standard format for containers
(stack of layers; 1 layer = tarball+metadata)
standard, reproducible way to easily build
trusted images (Dockerfile, Stackbrew...)
Docker-what?
Under The Hood
●

rewrite of dotCloud internal container engine
–
–

●

original version: Python, tied to dotCloud's internal stuff
released version: Go, legacy-free

the Docker daemon runs in the background
–

manages containers, images, and builds

–

HTTP API (over UNIX or TCP socket)

–

embedded CLI talking to the API

●

Open Source (GitHub public repository + issue tracking)

●

user and dev mailing lists

●

FreeNode IRC channels #docker, #docker-dev
Outline
●

Whom is this for?

●

What's the problem?

●

What's a Container?

●

Docker 101

●

Docker images

●

Docker deployment

●

Docker future
Authoring images
with run/commit
1) docker run ubuntu bash
2) apt-get install this and that
3) docker commit <containerid> <imagename>
4) docker run <imagename> bash
5) git clone git://.../mycode
6) pip install -r requirements.txt
7) docker commit <containerid> <imagename>
8) repeat steps 4-7 as necessary
9) docker tag <imagename> <user/image>
10) docker push <user/image>
Authoring images
with a Dockerfile
FROM ubuntu
RUN
RUN
RUN
RUN
RUN

apt-get
apt-get
apt-get
apt-get
apt-get

-y update
install -y
install -y
install -y
install -y

g++
erlang-dev erlang-manpages erlang-base-hipe ...
libmozjs185-dev libicu-dev libtool ...
make wget

RUN wget http://.../apache-couchdb-1.3.1.tar.gz | tar -C /tmp -zxfRUN cd /tmp/apache-couchdb-* && ./configure && make install
RUN printf "[httpd]nport = 8101nbind_address = 0.0.0.0" >
/usr/local/etc/couchdb/local.d/docker.ini
EXPOSE 8101
CMD ["/usr/local/bin/couchdb"]

docker build -t jpetazzo/couchdb .
Authoring Images
with Trusted Builds
0) create a GitHub account
On index.docker.io:
1) create a Docker account
2) link it with your GitHub account
3) enable Trusted Builds on any public repo
On your dev env:
4) git add Dockerfile
5) git commit
6) git push
Authoring Images
with Chef/Puppet/Ansible/Salt/...
Plan A: « my other VM is a container »
●

write a Dockerfile to install $YOUR_CM

●

start tons of containers

●

run $YOUR_CM in them

Good if you want a mix of containers/VM/metal
But slower to deploy, and uses more resources
Authoring Images
with Chef/Puppet/Ansible/Salt/...
Plan B: « the revolution will be containerized »
●

write a Dockerfile to install $YOUR_CM

●

… and run $YOUR_CM as part of build process

●

deploy fully baked images

Faster to deploy
Easier to rollback
Outline
●

Whom is this for?

●

What's the problem?

●

What's a Container?

●

Docker 101

●

Docker images

●

Docker deployment

●

Docker future
Running containers
SSH to Docker host and manual pull+run
● REST API (feel free to add SSL certs, OAUth...)
● maestro, maestro-ng
(https://github.com/signalfuse/maestro-ng)
● OpenStack Nova
● OpenStack Heat
● who's next? OpenShift, CloudFoundry?
● multiple Open Source PAAS built on Docker
●
Orchestration & Service Discovery
●

you can name your containers

●

they get a generated name by default
–
–

●

0.6: red_ant, gold_monkey...
0.7: angry_linus, naughty_tesla...

you can link your containers

docker run -d -name frontdb mysqlimage
docker run -d -link frontdb:sql nginximage
→ container frontweb gets one bazillion environment vars
Orchestration & Service
Discovery roadmap
●
●

●

currently single-host
problem:
how do I link with containers on other hosts?
solution:
ambassador pattern!
–

app container runs in its happy place

–

other things (Docker, containers...) plumb it
Orchestration roadmap
●
●

●

currently static
problem: what if I want to…
move a container?
do a master/slave failover?
WebScale my MangoDB cluster?
solution:
dynamic discovery!
Multi-host Docker deployments

I could give a full talk
about this topic
(and actually I did once)
Outline
●

Whom is this for?

●

What's the problem?

●

What's a Container?

●

Docker 101

●

Docker images

●

Docker deployment

●

Docker future
Docker: the community
●

Docker: >240 contributors

●

Docker inc.: <20 engineers

●

latest milestone (0.7): >100 contributors

●

~50% of all commits by external contributors

●

GitHub repository: >1000 forks

...and counting!
Docker long-term roadmap
Docker 1.0:
●

remove AUFS, THINP, LXC, etc.
–
–

●

storage? cp!

–
●

execution? chroot!
we can run everywhere o/

re-add everything as plugins
discover and interconnect hosts and services
through docker.io
Thank you! Questions?

http://docker.io/
http://docker.com/
https://github.com/dotcloud/docker
@docker
@jpetazzo

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Introduction to Docker
Introduction to DockerIntroduction to Docker
Introduction to Docker
 
Introduction to Docker at SF Peninsula Software Development Meetup @Guidewire
Introduction to Docker at SF Peninsula Software Development Meetup @GuidewireIntroduction to Docker at SF Peninsula Software Development Meetup @Guidewire
Introduction to Docker at SF Peninsula Software Development Meetup @Guidewire
 
Introduction to Docker and all things containers, Docker Meetup at RelateIQ
Introduction to Docker and all things containers, Docker Meetup at RelateIQIntroduction to Docker and all things containers, Docker Meetup at RelateIQ
Introduction to Docker and all things containers, Docker Meetup at RelateIQ
 
Lightweight Virtualization: LXC containers & AUFS
Lightweight Virtualization: LXC containers & AUFSLightweight Virtualization: LXC containers & AUFS
Lightweight Virtualization: LXC containers & AUFS
 
Docker 0.11 at MaxCDN meetup in Los Angeles
Docker 0.11 at MaxCDN meetup in Los AngelesDocker 0.11 at MaxCDN meetup in Los Angeles
Docker 0.11 at MaxCDN meetup in Los Angeles
 
JOSA TechTalk: Taking Docker to Production
JOSA TechTalk: Taking Docker to ProductionJOSA TechTalk: Taking Docker to Production
JOSA TechTalk: Taking Docker to Production
 
Hands on Virtualization with Ganeti (part 1) - LinuxCon 2012
Hands on Virtualization with Ganeti (part 1)  - LinuxCon 2012Hands on Virtualization with Ganeti (part 1)  - LinuxCon 2012
Hands on Virtualization with Ganeti (part 1) - LinuxCon 2012
 
Introduction to Docker, December 2014 "Tour de France" Bordeaux Special Edition
Introduction to Docker, December 2014 "Tour de France" Bordeaux Special EditionIntroduction to Docker, December 2014 "Tour de France" Bordeaux Special Edition
Introduction to Docker, December 2014 "Tour de France" Bordeaux Special Edition
 
[DockerCon 2020] Hardening Docker daemon with Rootless Mode
[DockerCon 2020] Hardening Docker daemon with Rootless Mode[DockerCon 2020] Hardening Docker daemon with Rootless Mode
[DockerCon 2020] Hardening Docker daemon with Rootless Mode
 
Containers, Docker, and Security: State Of The Union (LinuxCon and ContainerC...
Containers, Docker, and Security: State Of The Union (LinuxCon and ContainerC...Containers, Docker, and Security: State Of The Union (LinuxCon and ContainerC...
Containers, Docker, and Security: State Of The Union (LinuxCon and ContainerC...
 
Rootless Containers & Unresolved issues
Rootless Containers & Unresolved issuesRootless Containers & Unresolved issues
Rootless Containers & Unresolved issues
 
Lightweight Virtualization with Linux Containers and Docker | YaC 2013
Lightweight Virtualization with Linux Containers and Docker | YaC 2013Lightweight Virtualization with Linux Containers and Docker | YaC 2013
Lightweight Virtualization with Linux Containers and Docker | YaC 2013
 
Red Teaming macOS Environments with Hermes the Swift Messenger
Red Teaming macOS Environments with Hermes the Swift MessengerRed Teaming macOS Environments with Hermes the Swift Messenger
Red Teaming macOS Environments with Hermes the Swift Messenger
 
Docker in everyday development
Docker in everyday developmentDocker in everyday development
Docker in everyday development
 
Docker 101 - from 0 to Docker in 30 minutes
Docker 101 - from 0 to Docker in 30 minutesDocker 101 - from 0 to Docker in 30 minutes
Docker 101 - from 0 to Docker in 30 minutes
 
Docker_AGH_v0.1.3
Docker_AGH_v0.1.3Docker_AGH_v0.1.3
Docker_AGH_v0.1.3
 
[KubeCon EU 2021] Introduction and Deep Dive Into Containerd
[KubeCon EU 2021] Introduction and Deep Dive Into Containerd[KubeCon EU 2021] Introduction and Deep Dive Into Containerd
[KubeCon EU 2021] Introduction and Deep Dive Into Containerd
 
Introduction to Docker and deployment and Azure
Introduction to Docker and deployment and AzureIntroduction to Docker and deployment and Azure
Introduction to Docker and deployment and Azure
 
Seven problems of Linux Containers
Seven problems of Linux ContainersSeven problems of Linux Containers
Seven problems of Linux Containers
 
Introduction to Docker at Glidewell Laboratories in Orange County
Introduction to Docker at Glidewell Laboratories in Orange CountyIntroduction to Docker at Glidewell Laboratories in Orange County
Introduction to Docker at Glidewell Laboratories in Orange County
 

Similar a Introduction to Docker (as presented at December 2013 Global Hackathon)

Introduction to Docker and Containers
Introduction to Docker and ContainersIntroduction to Docker and Containers
Introduction to Docker and Containers
Docker, Inc.
 
Lightweight Virtualization with Linux Containers and Docker I YaC 2013
Lightweight Virtualization with Linux Containers and Docker I YaC 2013Lightweight Virtualization with Linux Containers and Docker I YaC 2013
Lightweight Virtualization with Linux Containers and Docker I YaC 2013
Docker, Inc.
 
A Gentle Introduction to Docker and Containers
A Gentle Introduction to Docker and ContainersA Gentle Introduction to Docker and Containers
A Gentle Introduction to Docker and Containers
Docker, Inc.
 
Why kernelspace sucks?
Why kernelspace sucks?Why kernelspace sucks?
Why kernelspace sucks?
OpenFest team
 

Similar a Introduction to Docker (as presented at December 2013 Global Hackathon) (20)

Docker Introduction, and what's new in 0.9 — Docker Palo Alto at RelateIQ
Docker Introduction, and what's new in 0.9 — Docker Palo Alto at RelateIQDocker Introduction, and what's new in 0.9 — Docker Palo Alto at RelateIQ
Docker Introduction, and what's new in 0.9 — Docker Palo Alto at RelateIQ
 
Docker and-containers-for-development-and-deployment-scale12x
Docker and-containers-for-development-and-deployment-scale12xDocker and-containers-for-development-and-deployment-scale12x
Docker and-containers-for-development-and-deployment-scale12x
 
Introduction to Docker and Containers
Introduction to Docker and ContainersIntroduction to Docker and Containers
Introduction to Docker and Containers
 
Lightweight Virtualization with Linux Containers and Docker I YaC 2013
Lightweight Virtualization with Linux Containers and Docker I YaC 2013Lightweight Virtualization with Linux Containers and Docker I YaC 2013
Lightweight Virtualization with Linux Containers and Docker I YaC 2013
 
A Gentle Introduction to Docker and Containers
A Gentle Introduction to Docker and ContainersA Gentle Introduction to Docker and Containers
A Gentle Introduction to Docker and Containers
 
"Lightweight Virtualization with Linux Containers and Docker". Jerome Petazzo...
"Lightweight Virtualization with Linux Containers and Docker". Jerome Petazzo..."Lightweight Virtualization with Linux Containers and Docker". Jerome Petazzo...
"Lightweight Virtualization with Linux Containers and Docker". Jerome Petazzo...
 
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!
 
Workshop : 45 minutes pour comprendre Docker avec Jérôme Petazzoni
Workshop : 45 minutes pour comprendre Docker avec Jérôme PetazzoniWorkshop : 45 minutes pour comprendre Docker avec Jérôme Petazzoni
Workshop : 45 minutes pour comprendre Docker avec Jérôme Petazzoni
 
Adhocr T-dose 2012
Adhocr T-dose 2012Adhocr T-dose 2012
Adhocr T-dose 2012
 
Docker Intro at the Google Developer Group and Google Cloud Platform Meet Up
Docker Intro at the Google Developer Group and Google Cloud Platform Meet UpDocker Intro at the Google Developer Group and Google Cloud Platform Meet Up
Docker Intro at the Google Developer Group and Google Cloud Platform Meet Up
 
Containers > VMs
Containers > VMsContainers > VMs
Containers > VMs
 
Introduction to containers
Introduction to containersIntroduction to containers
Introduction to containers
 
Techtalks: taking docker to production
Techtalks: taking docker to productionTechtalks: taking docker to production
Techtalks: taking docker to production
 
Puppet Camp Chicago 2014: Docker and Puppet: 1+1=3 (Intermediate)
Puppet Camp Chicago 2014: Docker and Puppet: 1+1=3 (Intermediate)Puppet Camp Chicago 2014: Docker and Puppet: 1+1=3 (Intermediate)
Puppet Camp Chicago 2014: Docker and Puppet: 1+1=3 (Intermediate)
 
Introduction to Docker at the Azure Meet-up in New York
Introduction to Docker at the Azure Meet-up in New YorkIntroduction to Docker at the Azure Meet-up in New York
Introduction to Docker at the Azure Meet-up in New York
 
Java in containers
Java in containersJava in containers
Java in containers
 
Docker and friends at Linux Days 2014 in Prague
Docker and friends at Linux Days 2014 in PragueDocker and friends at Linux Days 2014 in Prague
Docker and friends at Linux Days 2014 in Prague
 
The Accidental DBA
The Accidental DBAThe Accidental DBA
The Accidental DBA
 
Real-World Docker: 10 Things We've Learned
Real-World Docker: 10 Things We've Learned  Real-World Docker: 10 Things We've Learned
Real-World Docker: 10 Things We've Learned
 
Why kernelspace sucks?
Why kernelspace sucks?Why kernelspace sucks?
Why kernelspace sucks?
 

Más de Jérôme Petazzoni

Microservices. Microservices everywhere! (At OSCON 2015)
Microservices. Microservices everywhere! (At OSCON 2015)Microservices. Microservices everywhere! (At OSCON 2015)
Microservices. Microservices everywhere! (At OSCON 2015)
Jérôme Petazzoni
 

Más de Jérôme Petazzoni (20)

Use the Source or Join the Dark Side: differences between Docker Community an...
Use the Source or Join the Dark Side: differences between Docker Community an...Use the Source or Join the Dark Side: differences between Docker Community an...
Use the Source or Join the Dark Side: differences between Docker Community an...
 
Orchestration for the rest of us
Orchestration for the rest of usOrchestration for the rest of us
Orchestration for the rest of us
 
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...
 
Docker : quels enjeux pour le stockage et réseau ? Paris Open Source Summit ...
Docker : quels enjeux pour le stockage et réseau ? Paris Open Source Summit ...Docker : quels enjeux pour le stockage et réseau ? Paris Open Source Summit ...
Docker : quels enjeux pour le stockage et réseau ? Paris Open Source Summit ...
 
Making DevOps Secure with Docker on Solaris (Oracle Open World, with Jesse Bu...
Making DevOps Secure with Docker on Solaris (Oracle Open World, with Jesse Bu...Making DevOps Secure with Docker on Solaris (Oracle Open World, with Jesse Bu...
Making DevOps Secure with Docker on Solaris (Oracle Open World, with Jesse Bu...
 
Containers, docker, and security: state of the union (Bay Area Infracoders Me...
Containers, docker, and security: state of the union (Bay Area Infracoders Me...Containers, docker, and security: state of the union (Bay Area Infracoders Me...
Containers, docker, and security: state of the union (Bay Area Infracoders Me...
 
From development environments to production deployments with Docker, Compose,...
From development environments to production deployments with Docker, Compose,...From development environments to production deployments with Docker, Compose,...
From development environments to production deployments with Docker, Compose,...
 
How to contribute to large open source projects like Docker (LinuxCon 2015)
How to contribute to large open source projects like Docker (LinuxCon 2015)How to contribute to large open source projects like Docker (LinuxCon 2015)
How to contribute to large open source projects like Docker (LinuxCon 2015)
 
Anatomy of a Container: Namespaces, cgroups & Some Filesystem Magic - LinuxCon
Anatomy of a Container: Namespaces, cgroups & Some Filesystem Magic - LinuxConAnatomy of a Container: Namespaces, cgroups & Some Filesystem Magic - LinuxCon
Anatomy of a Container: Namespaces, cgroups & Some Filesystem Magic - LinuxCon
 
Microservices. Microservices everywhere! (At OSCON 2015)
Microservices. Microservices everywhere! (At OSCON 2015)Microservices. Microservices everywhere! (At OSCON 2015)
Microservices. Microservices everywhere! (At OSCON 2015)
 
Deploy microservices in containers with Docker and friends - KCDC2015
Deploy microservices in containers with Docker and friends - KCDC2015Deploy microservices in containers with Docker and friends - KCDC2015
Deploy microservices in containers with Docker and friends - KCDC2015
 
Containers: from development to production at DevNation 2015
Containers: from development to production at DevNation 2015Containers: from development to production at DevNation 2015
Containers: from development to production at DevNation 2015
 
Immutable infrastructure with Docker and containers (GlueCon 2015)
Immutable infrastructure with Docker and containers (GlueCon 2015)Immutable infrastructure with Docker and containers (GlueCon 2015)
Immutable infrastructure with Docker and containers (GlueCon 2015)
 
The Docker ecosystem and the future of application deployment
The Docker ecosystem and the future of application deploymentThe Docker ecosystem and the future of application deployment
The Docker ecosystem and the future of application deployment
 
Docker: automation for the rest of us
Docker: automation for the rest of usDocker: automation for the rest of us
Docker: automation for the rest of us
 
Docker Non Technical Presentation
Docker Non Technical PresentationDocker Non Technical Presentation
Docker Non Technical Presentation
 
Containers, Docker, and Microservices: the Terrific Trio
Containers, Docker, and Microservices: the Terrific TrioContainers, Docker, and Microservices: the Terrific Trio
Containers, Docker, and Microservices: the Terrific Trio
 
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 ...
 
Pipework: Software-Defined Network for Containers and Docker
Pipework: Software-Defined Network for Containers and DockerPipework: Software-Defined Network for Containers and Docker
Pipework: Software-Defined Network for Containers and Docker
 
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
 

Último

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 

Último (20)

Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 

Introduction to Docker (as presented at December 2013 Global Hackathon)

  • 1. a Gentle Introduction to Docker and All Things Containers December 2013—updated for Docker 0.7
  • 2. Outline ● Whom is this for? ● What's the problem? ● What's a Container? ● Docker 101 ● Docker images ● Docker deployment ● Docker future
  • 3. Outline ● Whom is this for? ● What's the problem? ● What's a Container? ● Docker 101 ● Docker images ● Docker deployment ● Docker future
  • 4. Devs ● all languages ● all databases ● all O/S ● targetting Linux systems Docker will eventually be able to target FreeBSD, Solaris, and maybe OS X.
  • 5. Ops ● any distro ● any cloud ● any machine (physical, virtual...) ● recent kernels – at least 3.8 – or the one that comes with RHEL 6.5
  • 6. CFO, CIO, CTO, ... ● LESS overhead! ● MOAR consolidation! ● MOAR agility! ● LESS costs!
  • 7. Outline ● Whom is this for? ● What's the problem? ● What's a Container? ● Docker 101 ● Docker images ● Docker deployment ● Docker future
  • 8. The Matrix From Hell django web frontend node.js async API background workers SQL database distributed DB, big data message queue ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? my laptop your laptop staging prod on cloud VM prod on bare metal QA
  • 9. Another Matrix from Hell ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
  • 12. Solution to the deployment problem: the Linux container
  • 13. Linux containers... Units of software delivery (ship it!) ● run everywhere – – regardless of host distro – ● regardless of kernel version (but container and host architecture must match*) run anything – if it can run on the host, it can run in the container – i.e., if it can run on a Linux kernel, it can run *Unless you emulate CPU with qemu and binfmt
  • 14. Outline ● Whom is this for? ● What's the problem? ● What's a Container? ● Docker 101 ● Docker images ● Docker deployment ● Docker future
  • 15. High level approach: it's a lightweight VM ● own process space ● own network interface ● can run stuff as root ● can have its own /sbin/init (different from the host) « Machine Container »
  • 16. Low level approach: it's chroot on steroids ● can also not have its own /sbin/init ● container = isolated process(es) ● share kernel with host ● no device emulation (neither HVM nor PV) « Application Container »
  • 17. Separation of concerns: Dave the Developer ● inside my container: – my code – my libraries – my package manager – my app – my data
  • 18. Separation of concerns: Oscar the Ops guy ● outside the container: – logging – remote access – network configuration – monitoring
  • 19. How does it work? Isolation with namespaces ● pid ● mnt ● net ● uts ● ipc ● user
  • 20. pid namespace jpetazzo@tarrasque:~$ ps aux | wc -l 212 jpetazzo@tarrasque:~$ sudo docker run -t bash root@ea319b8ac416:/# ps aux USER PID %CPU %MEM VSZ RSS TTY STAT COMMAND root 1 0.0 0.0 18044 1956 ? S root 16 0.0 0.0 15276 1136 ? R+ aux (That's 2 processes) -i ubuntu START TIME 02:54 02:55 0:00 bash 0:00 ps
  • 21. mnt namespace jpetazzo@tarrasque:~$ wc -l /proc/mounts 32 /proc/mounts root@ea319b8ac416:/# wc -l /proc/mounts 10 /proc/mounts
  • 22. net namespace root@ea319b8ac416:/# ip addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 22: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> pfifo_fast state UP qlen 1000 mtu 1500 qdisc link/ether 2a:d1:4b:7e:bf:b5 brd ff:ff:ff:ff:ff:ff inet 10.1.1.3/24 brd 10.1.1.255 scope global eth0 valid_lft forever preferred_lft forever inet6 fe80::28d1:4bff:fe7e:bfb5/64 scope link valid_lft forever preferred_lft forever
  • 24. ipc namespace jpetazzo@tarrasque:~$ ipcs ------ Shared Memory Segments -------key shmid owner perms 0x00000000 3178496 jpetazzo 600 0x00000000 557057 jpetazzo 777 0x00000000 3211266 jpetazzo 600 root@ea319b8ac416:/# ipcs ------ Shared Memory Segments -------key shmid owner perms ------ Semaphore Arrays -------key semid owner perms ------ Message Queues -------key msqid owner perms bytes 393216 2778672 393216 nattch 2 0 2 status dest bytes nattch status nsems used-bytes messages dest
  • 25. user namespace ● ● no « demo » for this one... Yet! UID 0→1999 in container C1 is mapped to UID 10000→11999 in host; UID 0→1999 in container C2 is mapped to UID 12000→13999 in host; etc. ● required lots of VFS and FS patches (esp. XFS) ● what will happen with copy-on-write? – double translation at VFS? – single root UID on read-only FS?
  • 26. How does it work? Isolation with cgroups ● memory ● cpu ● blkio ● devices
  • 27. How does it work? Isolation with cgroups ● memory ● cpu ● blkio ● devices
  • 28. memory cgroup ● keeps track pages used by each group: – file (read/write/mmap from block devices; swap) – anonymous (stack, heap, anonymous mmap) – active (recently accessed) – inactive (candidate for eviction) ● each page is « charged » to a group ● pages can be shared (e.g. if you use any COW FS) ● Individual (per-cgroup) limits and out-of-memory killer
  • 29. cpu and cpuset cgroups ● keep track of user/system CPU time ● set relative weight per group ● pin groups to specific CPU(s) – Can be used to « reserve » CPUs for some apps – This is also relevant for big NUMA systems
  • 30. blkio cgroups ● keep track IOs for each block device – read vs write; sync vs async ● set relative weights ● set throttle (limits) for each block device – read vs write; bytes/sec vs operations/sec Note: earlier versions (<3.8) didn't account async correctly. 3.8 is better, but use 3.10 for best results.
  • 31. devices cgroups ● controls read/write/mknod permissions ● typically: – allow: /dev/{tty,zero,random,null}... – deny: everything else – maybe: /dev/net/tun, /dev/fuse
  • 32. If you're serious about security, you also need… ● capabilities – okay: cap_ipc_lock, cap_lease, cap_mknod, cap_net_admin, cap_net_bind_service, cap_net_raw – troublesome: cap_sys_admin (mount!) ● think twice before granting root ● grsec is nice ● seccomp (very specific use cases); seccomp-bpf ● beware of full-scale kernel exploits!
  • 33. How does it work? Copy-on-write storage ● ● ● unioning filesystems (AUFS, overlayfs) snapshotting filesystems (BTRFS, ZFS) copy-on-write block devices (thin snapshots with LVM or device-mapper) Since 0.7, Docker has a storage plugin system!
  • 35. Compute efficiency: almost no overhead ● ● ● ● processes are isolated, but run straight on the host CPU performance = native performance memory performance = a few % shaved off for (optional) accounting network performance = small overhead; can be reduced to zero
  • 36. Storage efficiency: many options! Union Filesystems Snapshotting Filesystems Copy-on-write block devices Provisioning Superfast Supercheap Fast Cheap Fast Cheap Changing small files Changing large files Diffing Superfast Supercheap Fast Cheap Fast Costly Slow (first time) Inefficient (copy-up!) Fast Cheap Fast Cheap Superfast Superfast (ZFS) Kinda meh (BTRFS) Slow Memory usage Efficient Efficient Inefficient (at high densities) Drawbacks Random quirks AUFS not mainline !AUFS more quirks ZFS not mainline BTRFS not as nice Higher disk usage Great performance (except diffing) Bottom line Ideal for PAAS and high density things This might be the Future Dodge Ram 3500
  • 37. Outline ● Whom is this for? ● What's the problem? ● What's a Container? ● Docker 101 ● Docker images ● Docker deployment ● Docker future
  • 38.
  • 39. Docker-what? ● Open Source engine to commoditize LXC ● using copy-on-write for quick provisioning STOP! HAMMER DEMO TIME.
  • 40.
  • 41. Yes, but... ● ● ● « I don't need Docker; I can do all that stuff with LXC tools, rsync, and some scripts! » correct on all accounts; but it's also true for apt, dpkg, rpm, yum, etc. the whole point is to commoditize, i.e. make it ridiculously easy to use
  • 44. What this really means… ● instead of writing « very small shell scripts » to manage containers, write them to do the rest: – continuous deployment/integration/testing – orchestration ● = use Docker as a building block ● re-use other people images (yay ecosystem!)
  • 45. Docker-what? The Big Picture ● Open Source engine to commoditize LXC ● using copy-on-write for quick provisioning ● allowing to create and share images ● ● standard format for containers (stack of layers; 1 layer = tarball+metadata) standard, reproducible way to easily build trusted images (Dockerfile, Stackbrew...)
  • 46. Docker-what? Under The Hood ● rewrite of dotCloud internal container engine – – ● original version: Python, tied to dotCloud's internal stuff released version: Go, legacy-free the Docker daemon runs in the background – manages containers, images, and builds – HTTP API (over UNIX or TCP socket) – embedded CLI talking to the API ● Open Source (GitHub public repository + issue tracking) ● user and dev mailing lists ● FreeNode IRC channels #docker, #docker-dev
  • 47. Outline ● Whom is this for? ● What's the problem? ● What's a Container? ● Docker 101 ● Docker images ● Docker deployment ● Docker future
  • 48. Authoring images with run/commit 1) docker run ubuntu bash 2) apt-get install this and that 3) docker commit <containerid> <imagename> 4) docker run <imagename> bash 5) git clone git://.../mycode 6) pip install -r requirements.txt 7) docker commit <containerid> <imagename> 8) repeat steps 4-7 as necessary 9) docker tag <imagename> <user/image> 10) docker push <user/image>
  • 49. Authoring images with a Dockerfile FROM ubuntu RUN RUN RUN RUN RUN apt-get apt-get apt-get apt-get apt-get -y update install -y install -y install -y install -y g++ erlang-dev erlang-manpages erlang-base-hipe ... libmozjs185-dev libicu-dev libtool ... make wget RUN wget http://.../apache-couchdb-1.3.1.tar.gz | tar -C /tmp -zxfRUN cd /tmp/apache-couchdb-* && ./configure && make install RUN printf "[httpd]nport = 8101nbind_address = 0.0.0.0" > /usr/local/etc/couchdb/local.d/docker.ini EXPOSE 8101 CMD ["/usr/local/bin/couchdb"] docker build -t jpetazzo/couchdb .
  • 50. Authoring Images with Trusted Builds 0) create a GitHub account On index.docker.io: 1) create a Docker account 2) link it with your GitHub account 3) enable Trusted Builds on any public repo On your dev env: 4) git add Dockerfile 5) git commit 6) git push
  • 51. Authoring Images with Chef/Puppet/Ansible/Salt/... Plan A: « my other VM is a container » ● write a Dockerfile to install $YOUR_CM ● start tons of containers ● run $YOUR_CM in them Good if you want a mix of containers/VM/metal But slower to deploy, and uses more resources
  • 52. Authoring Images with Chef/Puppet/Ansible/Salt/... Plan B: « the revolution will be containerized » ● write a Dockerfile to install $YOUR_CM ● … and run $YOUR_CM as part of build process ● deploy fully baked images Faster to deploy Easier to rollback
  • 53. Outline ● Whom is this for? ● What's the problem? ● What's a Container? ● Docker 101 ● Docker images ● Docker deployment ● Docker future
  • 54. Running containers SSH to Docker host and manual pull+run ● REST API (feel free to add SSL certs, OAUth...) ● maestro, maestro-ng (https://github.com/signalfuse/maestro-ng) ● OpenStack Nova ● OpenStack Heat ● who's next? OpenShift, CloudFoundry? ● multiple Open Source PAAS built on Docker ●
  • 55. Orchestration & Service Discovery ● you can name your containers ● they get a generated name by default – – ● 0.6: red_ant, gold_monkey... 0.7: angry_linus, naughty_tesla... you can link your containers docker run -d -name frontdb mysqlimage docker run -d -link frontdb:sql nginximage → container frontweb gets one bazillion environment vars
  • 56. Orchestration & Service Discovery roadmap ● ● ● currently single-host problem: how do I link with containers on other hosts? solution: ambassador pattern! – app container runs in its happy place – other things (Docker, containers...) plumb it
  • 57. Orchestration roadmap ● ● ● currently static problem: what if I want to… move a container? do a master/slave failover? WebScale my MangoDB cluster? solution: dynamic discovery!
  • 58. Multi-host Docker deployments I could give a full talk about this topic (and actually I did once)
  • 59. Outline ● Whom is this for? ● What's the problem? ● What's a Container? ● Docker 101 ● Docker images ● Docker deployment ● Docker future
  • 60. Docker: the community ● Docker: >240 contributors ● Docker inc.: <20 engineers ● latest milestone (0.7): >100 contributors ● ~50% of all commits by external contributors ● GitHub repository: >1000 forks ...and counting!
  • 61. Docker long-term roadmap Docker 1.0: ● remove AUFS, THINP, LXC, etc. – – ● storage? cp! – ● execution? chroot! we can run everywhere o/ re-add everything as plugins discover and interconnect hosts and services through docker.io