59
INTRODUCTION TO by Tom Verelst Automation & Tooling Competence Center © 2016 JWorks

Introduction to Docker

Embed Size (px)

Citation preview

Page 1: Introduction to Docker

INTRODUCTION TO

by Tom Verelst

Automation & Tooling Competence Center

© 2016 JWorks

Page 2: Introduction to Docker

BEFORE WE BEGIN...Join https://tlk.io/ordina-docker

Page 3: Introduction to Docker

WHAT IS DOCKER?

Build Ship Run

Page 4: Introduction to Docker

WHAT IS A CONTAINER?

Contains the complete runtime environment

Application

Dependencies

Page 5: Introduction to Docker

It feels like a

LIGHTWEIGHT VIRTUAL MACHINEIt has a shell (SSH, ...)

Has its own namespace

Has its own network interface

Run stuff as root

Services

Packages

But if it's not a VM, so what's the difference?

Page 6: Introduction to Docker

VIRTUAL MACHINES

App

bins/libs

Guest OS

App

bins/libs

Guest OS

App

bins/libs

Guest OS

Hypervisor

Host OS / Kernel

Infrastructure

Page 7: Introduction to Docker

CONTAINERSProcesses that share the same kernel

App

bins/libs

App

bins/libs

App

bins/libs Daemon

Kernel

Infrastructure

Page 8: Introduction to Docker

DockerArchitecture

Page 9: Introduction to Docker

BASIC DOCKER WORKFLOW

Page 10: Introduction to Docker

DOCKER HOSTDocker Daemon

Docker Remote API (REST)

unix:///var/run/docker.sock

https://dockerhost:2376

Downloads and runs the containers

Page 11: Introduction to Docker

DOCKER CLIENTTalks to Docker daemon

Page 12: Introduction to Docker

DOCKER REGISTRYImage repository

Official Docker Registry @ hub.docker.com

As a service @ Docker Trusted Registry

Host your own @ github.com/docker/distribution

Page 13: Introduction to Docker

DOCKER IMAGEBasis for each container

Layers

Page 14: Introduction to Docker

LAYERSTop layer is thrown away when container stops

Writeable Container

Image: My application

Image: Java 8

Base Image: Ubuntu

bootfs (Kernel)

Page 15: Introduction to Docker

CONTENT ADDRESSABLE IMAGE IDSPreviously random UUIDs

Secure hash of image and layer data (SHA-256)

Separation of images and layers

ID collision prevention

Data integrity

Migration needed from pre-1.10

Page 16: Introduction to Docker

VOLUMES

Write and read data from outside

Mount local folders onto the container

Docker Volume drivers available

Page 17: Introduction to Docker

Basic Docker

Page 18: Introduction to Docker

DEMO TIME!

Page 19: Introduction to Docker

Commands

Page 20: Introduction to Docker

DOCKERFILEInstructions to automate building of your image

Steps are cached for fast-reuse

FROM java:8

COPY target/application.jar app.jar

ENTRYPOINT ["java", "-jar", "app.jar"]

Page 21: Introduction to Docker

BASIC DOCKER COMMANDS# Build the image in the working directory $ docker build -t myapp .

# Run the image we just built as a container $ docker run --name mycontainer myapp

# Stop the container $ docker stop mycontainer

# Start the container again $ docker start mycontainer

Page 22: Introduction to Docker

MANAGE CONTAINERS AND IMAGES# List running containers $ docker ps

# List all containers, including stopped $ docker ps -a

# List all images $ docker images

# Remove an image $ docker rmi myapp

Page 23: Introduction to Docker

PUSH DOCKER IMAGES TO THE REGISTRY# Login to Docker Registry $ docker login --username=tomverelst [email protected]

# Push the image to the Docker Registry $ docker push myapp

Page 24: Introduction to Docker

HOW DO CONTAINERS REALLY WORK?

Page 25: Introduction to Docker

WARNINGReal low-level Linux stuff ahead!

Page 26: Introduction to Docker

BACK TO 2007, KERNEL 2.6.24

Control Groups aka cgroups

Kernel feature

Linux Containers aka lxc

Linux package that uses cgroups

Page 27: Introduction to Docker

CONTROL GROUPResource limiting

Prioritization

Accounting

Controlling

Page 28: Introduction to Docker

LINUX CONTAINERSPackage

Different on different Linux distro's

Page 29: Introduction to Docker

REDESIGN IN 2013

KERNEL 3.15 AND 3.16

NAMESPACE ISOLATIONPID namespace

Network namespace

Hostname

Mount namespace

Inter-process communication namespace

User namespace

Page 30: Introduction to Docker

FIRST DOCKER RELEASE IN 2013Depended on LXC

Now abstracted with libcontainer

Page 31: Introduction to Docker

Benefits of containerisation

Page 32: Introduction to Docker

SCALING

Page 33: Introduction to Docker

IMMUTABLE INFRASTRUCTURE

Page 34: Introduction to Docker

DevOps

DEVApplication and dependencies

Inside of the container

OPSInfrastructure

Outside of the container

Page 35: Introduction to Docker

CONTINUOUS INTEGRATIONSame artifact for all environments

No more "It worked on my laptop"

Run your builds and tests inside containers

Page 36: Introduction to Docker

Orchestration

Compose Machine Swarm Networking

Page 37: Introduction to Docker

Compose

Define and run multi-container applications

Single host

Multi-host experimental

Page 38: Introduction to Docker

Machine

Create and provision machines as Docker hosts

Page 39: Introduction to Docker

Create new Docker hosts

Run containers on these new hosts

Page 40: Introduction to Docker

Drivers

Page 41: Introduction to Docker

Swarm

Clustering tool

Turn multiple hosts into one virtual host

Service discovery

Scheduling

Page 42: Introduction to Docker
Page 43: Introduction to Docker

LABELSDefine custom labels to your Docker host

$ docker daemon --label env="production" --label storage="ssd"

$ docker-machine --engine-label env="production" --label storage="ssd"

$ docker run -e constraint:env==production -e constraint:storage==ssd ...

Page 44: Introduction to Docker

Filters

NODEConstraint

Health

 

CONTAINERAffinity

Port

Dependency

Page 45: Introduction to Docker

Networking

Create overlay networks

Replaces links (bridge)

Network plugins (Weave)

Embedded DNS server

Page 46: Introduction to Docker

Compose + Swarm Production Ready?

NOPE

https://github.com/docker/compose/issues/2866

Page 47: Introduction to Docker

https://cloud.docker.com/

(Tutum: )https://www.tutum.co/

Page 48: Introduction to Docker

Tools

Page 49: Introduction to Docker

Kubernetes

Page 50: Introduction to Docker
Page 51: Introduction to Docker
Page 52: Introduction to Docker

etcd etcd etcdDocker Docker Docker

CoreOS host CoreOS host CoreOS host

Host #1 Host #2 Host #3

etcd

fleetctl

etcdctl

fleetd

nServices

systemd service files pool

Docker containers

Docker containers

Docker containers

Local machine

Page 53: Introduction to Docker

Lattice

Page 54: Introduction to Docker

Flocker

Data Volume Manager

Page 55: Introduction to Docker
Page 56: Introduction to Docker

CONTAINER SECURITYIsolation

Dependencies

Seccomp profiles

Coming soon: Unikernels

Security patches

Page 57: Introduction to Docker

NODE SECURITYDaemon must run as root

Default authorization is all or nothing

Authorization plugins

Page 58: Introduction to Docker

Roadmap

Page 59: Introduction to Docker

Thank You!

Automation & Tooling Competence Center

© 2016 JWorks