Who am I?

Joan Fuster
SysOps Engineer @ Ticketbis
jfusterm @ Github
joan.fuster@gmail.com

2

Agenda
– Introduction
– Docker Architecture
– Conclusions

There will be demos down the road 🙂

3

What we are going to learn?

What is Docker
What is a container
What problem does it solve
Why containers and microservices are
so popular right now
– Container vs VMs
– Docker architecture
– Typical Docker uses
4

Introduction
5

What is the problem here?

6

What is Docker?

“Platform to develop,
ship and run
applications into
containers”
7

What is a container?
– A full isolated runtime environment
– That environment includes everything
you need for your app:
– Filesystem
– Runtime
– Code
– Libraries
– It is not a mini-VM, it is just a
process
8

9

Why is it important?

Portability
No more dependency hell
No more dev/stage/prod problems
Idempotent
Easy to scale
More control for Devs
Less headaches for Ops
Redefines how applications are
deployed (faster)
10

Containers vs Virtual Machines

Source: Docker

11

Containers vs Virtual Machines
Containers

Process
MB
ms to boot
Higher density

VMs

Full OS
GB
Minutes to boot
Fewer density

12

Rise of the Microservices

Source: Docker

13

Docker
Architecture
14

Docker underlying technology
– Linux kernel ≥ 3.10 (recommended ≥ 4.0)
– cgroups (resource allocation)
– namespaces (isolation)
– unionFS (copy-on-write strategy)
– seccomp (system calls)
– capabilities (privileges)
– selinux/apparmor (security)
– Iptables (networking)
15

Docker components

Images
Containers
Registries
Services (≥ Docker Engine v1.12)

16

Docker images
– Build component of Docker
– Container’s base (think of a template)
– Uses UnionFS (implements a union mount
for other file systems)
– Composed of multiple layers
– A layer is a difference in the
filesystem
– Created from Dockerfiles (mainly)
17

Image layers

Source: Docker

18

Image layers

Source: Digital Ocean

19

Container layers

Source: Docker

20

Docker storage drivers
– Responsible for
– Docker can only
– Each driver has
implementation,

managing the layers
run one storage driver
a different
so perform differently

21

Supported storage drivers

OverlayFS
AUFS
Devicemapper
BTRFS
ZFS

22

Dockerfiles

Instructions to build the image
Uses a DSL (Domain Specific Language)
Automate the build
Instructions executed sequentially
Can be put under version control (Git)
Repeatable

23

Dockerfiles

FROM debian:jessie
RUN apt-get install -y emacs
RUN apt-get install -y apache2

$ docker build -t my-image:test .
24

Dockerfile main instructions

FROM (sets the base image)
ENV (sets environment variables)
RUN (execute commands)
COPY (copies files to the image)
EXPOSE (open ports at runtime)
ENTRYPOINT (defines the executable)
CMD (provide defaults for a container
and params to the entrypoint)
25

Dockerfile example – Good
FROM ubuntu:16.04
RUN apt-get update
RUN apt-get install -y nginx
COPY index.html /var/www/html/
EXPOSE 80
ENTRYPOINT [“/usr/sbin/nginx”,”-g”,”daemon
off;”]

26

Dockerfile example – Better
FROM ubuntu:16.04
RUN apt-get update && \
apt-get install -y nginx && \
rm -rf /var/lib/apt/lists/*
COPY index.html /var/www/html/
EXPOSE 80
ENTRYPOINT [“/usr/sbin/nginx”,”-g”,”daemon
off;”]
27

Base images
– The base image on which the
instructions will be executed
– Different flavours
– Each image has different sizes

28

Base images examples

centos:7 (196.5MB)
ubuntu:16.04 (127.2MB)
debian:jessie (123MB)
opensuse:latest (95.76MB)
alpine:3.4 (4.8MB)

29

Dockerfile example – Best
FROM alpine:3.4
RUN apk –no-cache add nginx && \
mkdir /run/nginx
COPY index.html /var/lib/nginx/html
EXPOSE 80
ENTRYPOINT [“/usr/sbin/nginx”,”-g”,”daemon
off;”]

30

Docker containers

Run component of Docker
Containers are built from a Docker image
Execution environment
Can contain one (microservices) or more
processes
– A docker container exits when its main
process finishes

31

Docker registries
– Distribution component of Docker
– Service where the Docker images are
stored
– Docker Registry / Trusted Registry
– Docker Hub
– Quay.io
– AWS EC2 Container Registry (ECR)
32

Docker services
– Scalability component of Docker
– Basic unit in a Docker Swarm
– Desired state of your application

33

Docker architecture

34

Docker Tools

Docker
Docker
Docker
Docker
Docker
Docker
Docker

Engine
Hub
Machine
Compose
Registry
Swarm
Cloud
35

Docker Engine
– Container runtime
– Available for Linux, Mac & Windows
– 3 major components:
– Daemon
– REST API
– CLI

36

Docker Engine

Source: Docker

37

Some Docker Engine commands
$
$
$
$
$
$
$
$

docker
docker
docker
docker
docker
docker
docker
docker

info
version
run
build
ps
images
start
stop

$
$
$
$
$
$
$
$

docker
docker
docker
docker
docker
docker
docker
docker

restart
rm
rmi
port
inspect
exec
tag
attach
38

$ docker run hello-world

39

$ docker run -it ubuntu bash

i: Attach container’s STDIN
t: Allocate a pseudo-TTY (aka terminal)
ubuntu: Ubuntu image
bash: Command to run in the container
40

$ docker run -d –name nginx
-p 80:80 nginx

41

Docker Hub

Docker Registry cloud service
Public and private repositories
Official images are stored in Docker Hub
Automated build triggered by changes
Webhooks
Github and Bitbucket integration

42

Docker Machine
– Create Docker hosts on:
– Local computer
– Data Center
– Cloud Provider
– Typically used to provision Docker
on Windows and Mac

43

Docker Compose
– Used to define and run multi-container
applications
– Defined in a YAML file
(docker-compose.yml)
– Great for testing environments

44

Docker Compose
version: ‘2’
services:
app:
image: php
ports:
– “80:80”
– “443:443”
volumes:
– code:/var/www/html
links:
– mysql
mysql:
image: mysql:5.7
ports:
– “3306:3306”
volumes:
code: {}
45

Docker Registry
– Docker images storage
– Used to store Docker images in-house
– Commercially supported with Trusted
Registry

46

Docker Swarm
– Docker clustering solution
– Failover and high availability
containers
– Since v1.12 integrated in Docker Engine
– Built-in orchestration, service
discovery and load balancer
– Multi-host networking
– Declarative service model
47

Docker Swarm Nodes

Source: Docker

48

Docker Swarm Services

Source: Docker

49

Docker Cloud
– Cloud platform to manage and deploy
Docker containers
– Integrates all the Docker tools
– CaaS (Container as a Service)

50

Conclusions

51

Docker use cases

Legacy applications
CI/CD
Sandboxes
Microservices
Immutable infrastructure
Server consolidation

52

Challenges

Monitoring
Networking
Data persistence
Service discovery
Orchestration

– All together…
53

Container OS

CoreOS
RancherOS
Atomic
Snappy
Mesosphere DCOS
PhotonOS

54

That’s all folks!

Q&A
Thank you 🙂
55

Author: Jeroen Derks

Jeroen is the founder of the Alicante Tech meetup group. His current day job is to mostly build all kinds of applications, ranging from IoT to educational to corporate.

Leave a Reply