Introduction to docker

68
Introduction to Introduction to docker docker

description

Docker overview, building blocks and short tutorial.

Transcript of Introduction to docker

Page 1: Introduction to docker

Introduction to Introduction to dockerdocker

Page 2: Introduction to docker
Page 3: Introduction to docker

What will be in this talk

- Overview of docker features- Overview of docker building blocks- Comparison to other solutions- Quick docker tutorial- Dockerfile tips

Page 4: Introduction to docker

What will not be in this talk

- Exploiting docker- Details of deploying docker infrastructure- Deep technical descriptions

Page 5: Introduction to docker

Easy to learn

Page 6: Introduction to docker

- Easy to learn- Easy to learn- Cool whale- Cool whale- Written in go- Written in go

Page 7: Introduction to docker

But seriously?But seriously?

Page 8: Introduction to docker

Architecture changes

http://martinfowler.com/articles/microservices/images/decentralised-data.png

Page 9: Introduction to docker

Features - images

● Package every app in the same box (dependencies, working everywhere)

● Isolate things from each other● Standarized build procedure (Dockerfile)

Page 10: Introduction to docker

ContainersContainers

Page 11: Introduction to docker

Features - containers

● Managing containers– Running & stopping

– Inspect, logs, top, ps

– Save & load (from files)

– Diff & commit

● Mounting volumens– Share data

– Persistency

● Easy networking and linking containers

Page 12: Introduction to docker

Works on Works on everyone'severyone's machinemachine

Page 13: Introduction to docker

IsolationIsolation

Page 14: Introduction to docker

PortabilityPortability

Page 15: Introduction to docker

Features - workflow

● Docker deamon and cli● Docker hub and registry● Image versioning (pull, commit, pull, layers)

Page 16: Introduction to docker

Docker building Docker building blocksblocks

Page 17: Introduction to docker

How it's How it's cooked?cooked?

Page 18: Introduction to docker

NamespacesNamespaces

http://blog.dotcloud.com/under-the-hood-linux-kernels-on-http://blog.dotcloud.com/under-the-hood-linux-kernels-on-dotcloud-partdotcloud-part

Page 19: Introduction to docker

One of the overall goals of namespaces is to support the implementation of containers, a tool for lightweight virtualization.

Namespaces - GOAL

Page 20: Introduction to docker

Wrap a particular global system resource in an abstraction that makes it appear to the processes within the namespace that they have their own isolated instance of the global resource

Namespaces - HOW

Page 21: Introduction to docker

Processes 'think' that they are the only processes on the system

Namespaces - Result

Page 22: Introduction to docker

- pid

- numbering

- hierarchy

- cannot kill / ptrace in other namespaces

- net

- 20 apaches at 80

- mount

Namespaces - Examples

Page 23: Introduction to docker

Control Control groupsgroups

http://blog.dotcloud.com/kernel-secrets-from-the-paas-garage-http://blog.dotcloud.com/kernel-secrets-from-the-paas-garage-part-24-cpart-24-c

Page 24: Introduction to docker

Measure and limit resource usage for groups of

processes

Control groups

Page 25: Introduction to docker

Docker vs VMDocker vs VM

Page 26: Introduction to docker

Overhead

http://www.zdnet.com/what-is-docker-and-why-is-it-so-darn-popular-7000032269/

Page 27: Introduction to docker

LightweightLightweightAndAndfastfast

Page 28: Introduction to docker

Sharing OSSharing OS

Page 29: Introduction to docker

Higher densityHigher density

Page 30: Introduction to docker

Not really a VMNot really a VM

Page 31: Introduction to docker

Why docker? Why docker? Why not lxc?Why not lxc?

Page 32: Introduction to docker

Why docker? Why docker? Why not lxc?Why not lxc?

Page 33: Introduction to docker

Why docker? Why docker? Why not lxc?Why not lxc?

Page 34: Introduction to docker

Why docker? Why docker? Why not lxc?Why not lxc?

http://stackoverflow.com/questions/17989306/what-does-docker-add-to-just-plain-lxc

Page 35: Introduction to docker

Docker tutorialDocker tutorial

Page 36: Introduction to docker

Pull it!Pull it!$ docker pull busybox

● Search docker registry for repository of given name

● Downloads the repository

● Pulls only changes next time

Page 37: Introduction to docker

Pull it!Pull it!$ docker pull busybox

● Search docker registry for repository of given name

● Downloads the repository

● Pulls only changes next time

Page 38: Introduction to docker

Pull it!Pull it!$ docker pull busybox

● Search docker registry for repository of given name

● Downloads the repository

● Pulls only changes next time

Page 39: Introduction to docker
Page 40: Introduction to docker

Run it!Run it!$ docker run busybox:ubuntu-14.04 echo "hello"

● Make sure that image is available (downloads if not found)

● Create a container● Run a command

Page 41: Introduction to docker

Run it!Run it!$ docker run -it busybox:ubuntu-14.04 sh

● -it → makes container interactive

● Create a container● Give you a shell

access

Page 42: Introduction to docker

More complicated example

● Run redis in a container

● Run it as a deamon

● Bind it to network● Make storage

persistent

Page 43: Introduction to docker

Run it!Run it!$ docker run -d -v /var/docker/redis:/data -p 6379:6379 --name=redis dockerfile/redis

● -d → launch as deamon

● -v /var/docker/redis:/data → mount directories

● -p 6379:6379 → forward ports

Page 44: Introduction to docker

Run it!Run it!$ docker run -d -v /var/docker/redis:/data -p 6379:6379 --name=redis dockerfile/redis

● -d → launch as deamon

● -v /var/docker/redis:/data → mount directories

● -p 6379:6379 → forward ports

Page 45: Introduction to docker

Run it!Run it!$ docker run -d -v /var/docker/redis:/data -p 6379:6379 --name=redis dockerfile/redis

● -d → launch as deamon

● -v /var/docker/redis:/data → mount directories

● -p 6379:6379 → forward ports

Page 46: Introduction to docker

Watch it!Watch it!

$ docker ps

Prints out information about docker containers

Page 47: Introduction to docker

Watch it!Watch it!

$ docker ps -a

Prints out information about all docker containers:

● Running● Exited

Page 48: Introduction to docker

Watch it!Watch it!

$ docker logs -t --follow romantic_enstein

Get logs from stdin/stdout of container

● -t → show timestamp● --follow → similar to

tail -f

Page 49: Introduction to docker

Watch it!Watch it!

$ docker inspect romantic_enstein

Get info about container

● Environment variables

● Ports● Links

Page 50: Introduction to docker

Enter Enter inside!inside!

- nsenter

- ssh

● nsenter uses namespaces

● Ssh needs ssh server inside

Page 51: Introduction to docker

Tidy upTidy up- docker rm <container_id>

- docker rmi <image_id>

● Docker images use lots of space

● Docker images can clog all your available space on server (no more pulling from registry)

Page 52: Introduction to docker

Tidy upTidy up$ docker ps -a | grep 'Exited' | awk '{print $1}' | xargs docker rm

● Get ids of exited containers● Remove containers with given ids

Page 53: Introduction to docker

Repository Repository workflowworkflow● docker diff <container_id>● docker commit

<contaner_id> attero/stuff:my-tag

● Versioning!● Tags● Multiple versions● Push & pull

Page 54: Introduction to docker

What we learned so farWhat we learned so far

Repository workflow– Pull

– Commit

– Push

Tidying up after containers– Rm

– Rmi

Monitoring– Ps

– Logs

– Inspect

– Top

Running containers– Interactive

– Deamon

– Mounting

– Forwarding

Page 55: Introduction to docker

Containers are nice

Page 56: Introduction to docker

How about automation?

Page 57: Introduction to docker

DOCKERFILE

Page 58: Introduction to docker

DOCKERFILE

- Version control- Automation- Portability

Page 59: Introduction to docker

DOCKERFILE

FROM ubuntu

MAINTAINER [email protected]

# Install tmuxRUN \ apt-get update && apt-get install tmux

RUN mkdir /home/hello

# Define working directory.WORKDIR /home/hello

# Define default command.CMD ["/bin/bash"]

Page 60: Introduction to docker

DOCKERFILE

FROM ubuntu ← defines base imag

MAINTAINER [email protected] ← who is reponsible

# Install tmuxRUN \ apt-get update && apt-get install tmux

RUN mkdir /home/hello ← let's run some commands

# Define working directory.WORKDIR /home/hello ← let's start here

# Define default command.CMD ["/bin/bash"] ← default command to run without arguments in run

Page 61: Introduction to docker

DOCKERFILE

Every command in Dockerfile is run on a different container

Page 62: Introduction to docker

DOCKERFILE

Don't start services in dockerfile.

Page 63: Introduction to docker

DOCKERFILE

Cache!- use it- save lots of time- not changed layers are reused

Page 64: Introduction to docker

DOCKERFILE

- short- good base image- most changing things at the bottom

Page 65: Introduction to docker

DOCKERFILE

Every command in Dockerfile is run on a different container

Page 66: Introduction to docker

Learning resources

● http://docs.docker.com/#installation-guides● http://docs.docker.com/reference/builder/● http://docs.docker.com/reference/commandline/cli

/● https://crosbymichael.com/dockerfile-best-practic

es.html● http://docs.docker.com/articles/basics/● https://www.youtube.com/watch?v=XCVOxht34H

s● https://www.youtube.com/watch?v=9bvdc55xYdo

Page 67: Introduction to docker

More Learning resources

● https://www.digitalocean.com/community/tutorials/docker-explained-how-to-containerize-python-web-applications

● http://phusion.github.io/baseimage-docker/● https://circleci.com/docs/docker● http://docs.docker.com/userguide/usingdocker/

Page 68: Introduction to docker

Q&A