Slide 1

Slide 1 text

Introduction to containers and Docker By Santiago Lizardo

Slide 2

Slide 2 text

2 2 whoami Santiago Lizardo • Manager • Software engineer at heart • +4 years at SolarWinds  We want YOU! https://solarwinds.jobs/gbr/jobs/ • Some years playing with Docker...

Slide 3

Slide 3 text

Introduction to containers and Docker Agenda • History • Using Docker containers  Demo: Hello world, Ubuntu, MySQL, Apache • Building Docker images  Demo: Creation of “solarwinds/webapp” image containining Apache + PHP + MySQL connector • Multi-container apps with Docker  Demo: MySQL + “solarwinds/webapp” Bonus content • Docker under the hood

Slide 4

Slide 4 text

History 4

Slide 5

Slide 5 text

5 5 In the beginning there was only darkness…

Slide 6

Slide 6 text

6 In the beginning there was only darkness…

Slide 7

Slide 7 text

7 In the beginning there was only darkness…

Slide 8

Slide 8 text

8 8

Slide 9

Slide 9 text

9 9

Slide 10

Slide 10 text

10 10

Slide 11

Slide 11 text

11 11

Slide 12

Slide 12 text

12 12

Slide 13

Slide 13 text

13 13 PHP 5.6 PHP 7.2

Slide 14

Slide 14 text

14 14 PHP 5.6 PHP 7.2

Slide 15

Slide 15 text

15 System diversity matrix

Slide 16

Slide 16 text

16 Transportation metaphor matrix

Slide 17

Slide 17 text

17 Invention of the shipping container

Slide 18

Slide 18 text

18 Transportation metaphor applied to software distribution

Slide 19

Slide 19 text

19 Docker history

Slide 20

Slide 20 text

20 Docker alternatives

Slide 21

Slide 21 text

Docker popularity stats Since it started in March 2013...

Slide 22

Slide 22 text

22 Docker and Kubernetes trends https://trends.google.com/trends/explore?date=today%205-y&q=docker,kubernetes,xen,virtualbox,vmware

Slide 23

Slide 23 text

23 Docker elevator pitch Docker is an open platform for developing, shipping, and running applications. Docker allows you to package an application with all of its dependencies into a standardized unit for software development.

Slide 24

Slide 24 text

Docker containers 24

Slide 25

Slide 25 text

25

Slide 26

Slide 26 text

26 What is a container? • Standardized packaging for software and dependencies • Isolate apps from each other • Share the same OS kernel • Works for all major Linux distributions • Containers native to Windows Server 2016

Slide 27

Slide 27 text

27 Docker vs virtualization • Lighter than virtual machines  Size of docker images are very small  Containers have less startup time  More efficiency without the OS overhead We can run more docker containers than VMs on a same box •Deploying and scaling is relatively easy

Slide 28

Slide 28 text

28 What is a container?

Slide 29

Slide 29 text

29 Worries

Slide 30

Slide 30 text

30 Key benefits of Docker containers Devs  Predictability: Build once, run anywhere o Consistent between environments  Portable: Bundled dependencies  Isolation: No application clashing  Scriptable  Efficiency: o Setup dev environments in seconds  Testability o Images are snapshots o Automation o Integration o Packaing  Continuous integration Ops  Flexibility: Configure once, run anything  Consistency: Identical environments o Test, staging, production, …  Efficiency: o Better resources (disk, CPU, RAM) utilisation – compared to VMs- o Faster restarts and deployments  Easy to scale

Slide 31

Slide 31 text

31 Basic terminology Image The basis of a Docker container. The content at rest Container The image when it's running. The standard unit for app service Engine The software that executes commands for containers. Networking and volumes are part of the Engine. Can be clustered together. Registry Stores, distributes and manages Docker images Control panel Management plane for container and cluster orchestration

Slide 32

Slide 32 text

32 Docker volumes

Slide 33

Slide 33 text

33 Docker volumes • Volumes mount a directory on the host into the container at a specific location $ docker volume create world_volume world_volume $ docker run -d -v world_volume :/world busybox ls /world • Can be used to share (and persist) data between containers • Directory persists after the container is deleted • Unless you explicitly delete it • Can be created in a Dockerfile or via CLI

Slide 34

Slide 34 text

34 34 Basic information Version Info Stats Help (help run) Running Run • Interactive mode • Detached • Port mapping • Volume mapping Inspecting Logs Port Inspect (--format ) Top container ls Image ls (-all) Stopping stop (SIGTERM + SIGKILL) kill (SIGKILL) container rm

Slide 35

Slide 35 text

Docker images 35

Slide 36

Slide 36 text

36 Base images and commits • Connect to the box • Make changes • Commit docker pull nginx docker run --name nginx-template-base -p 8080:80 -e TERM=xterm -d nginx docker exec -it CONTAINER_ID bash $ apt-get install nano $ exit docker commit CONTAINER_ID nginx-template - Better use Dockerfile

Slide 37

Slide 37 text

37 Dockerfile • Instructions on how to build a Docker image • Similar to native commands • It can be version controlled

Slide 38

Slide 38 text

38 Dockerfile (windows)

Slide 39

Slide 39 text

39 Docker layers

Slide 40

Slide 40 text

40 Docker layers

Slide 41

Slide 41 text

41 Copy on Write • Super efficient:  Sub second instantiation times for containers  New container can take <1 Mb of space • Containers appears to be a copy of the original image • But, it is really just a link to the original shared image • If someone writes a change to the file system, a copy of the affected file/directory is “copied up”

Slide 42

Slide 42 text

42 Dockerfile commands •FROM — set base image •RUN — execute command in container •ENV — set environment variable •WORKDIR — set working directory •COPY – Copies files from host to image •VOLUME — create mount-point for a volume •CMD — set executable for container

Slide 43

Slide 43 text

43 43 Registries Pull Push Building Build –t . Tagging Tag sourcetag targettag Removing image rm

Slide 44

Slide 44 text

Demo:

Slide 45

Slide 45 text

Multi-container apps with Docker 45

Slide 46

Slide 46 text

46 Multi-container apps Without compose • Build and run one container at a time • Manually connect containers together • Must be careful with dependencies and startup order With compose • Define multi container app in compose.yml file • Single command to deploy entire app • Handles container dependencies • Works with Docker Swarm, Networking, Volumes, Universal Control Plane

Slide 47

Slide 47 text

47 Multi-container apps

Slide 48

Slide 48 text

Docker under the hood 48

Slide 49

Slide 49 text

49 49 Technology behind Docker • Linux x86-64 • Go language • Client - Server (deamon) architecture • Union file systems (UnionFS: AUFS, btrfs, vfs etc) • Namespaces (pid, net, ipc, mnt, uts) • Control Groups (cgroups) • Container format (libcontainer)

Slide 50

Slide 50 text

50 50 •High level: a lightweight VM •Own process space •Own network interface •Can run stuff as root •Can have its own /sbin/init (different from host) <> •Low level: chroot on steroids •Can also not have its own /sbin/init •Container = isolated processes •Share kernel with host <>

Slide 51

Slide 51 text

51 Technology behind Docker • Control groups  Key component of Linux Containers  Implement resource accounting and limiting  Ensure each container gets its fair share of memory, CPU, disk I/O  Cgroup ensures a single container cannot bring the system down by exhausting resources • Union file systems  Layered file system so you can have a read only part and a write part, and merge those together  Docker images made up with are layers

Slide 52

Slide 52 text

52 Technology behind Docker • Namespaces  It helps to create isolated workspace for each process  Namespaces are created every time you run a container • SELinux  SELinux provides secure separation of containers by applying SELinux policy and label

Slide 53

Slide 53 text

Q&A