Rafael Martins

rafael84@gmail.com

 

Jan, 2015

What's Docker?

$ docker --help

Usage: docker [OPTIONS] COMMAND [arg...]

A self-sufficient runtime for linux containers.

So... what's a

LINUX CONTAINER

again?

First things first

Virtual Machines

Virtual Machine

Server

OS

?

OS

OS

OS

VM

guest os

}

host os

}

VM

VM

HYPERVISOR

Hypervisor

A piece of computer software, firmware or hardware that creates and runs virtual machines.

Hypervisor Types

Server

Hypervisor (type 1)

Server

Host OS

Hypervisor (type 2)

  • Hyper-V
  • XenServer
  • KVM
  • VMware Fusion
  • Oracle VirtualBox
  • Parallels Desktop for Mac

So far so good?

Virtual Machines

vs

Containers

VMs

Server

Host OS

Hypervisor (type 2)

Guest OS

Guest OS

Bins /
Libs

Bins /
Libs

App

A

App

B

Server

Host OS

Bins / Libs

Bins / Libs

App

A'

Containers

vs

App

A'

App

A'

App

A'

App

B'

App

B'

Guest OS

Bins /
Libs

App

A

Container Manager

VMs

Containers

vs

  • Emulate virtual hardware
  • FAT in terms of system requirements
  • Need a Guest OS for each instance
  • Usually, Guest OS resources must be defined upfront (amount of RAM, for instance)
  • Are SLOW
  • Share Host OS resources
  • May share Libs / Bins
  • Ultra lightweight in terms of system requirements
  • Are FAST. Really, really FAST!

What's Docker?

$ docker --help

Usage: docker [OPTIONS] COMMAND [arg...]

A self-sufficient runtime for linux containers.

Server

Host OS

Bins / Libs

Bins / Libs

App

A'

App

A'

App

A'

App

A'

App

B'

App

B'

Docker Engine

App

A'

CLI

Rest API

Dockerfiles

Container Manager

Docker

Registry

Docker

HUB (PaaS)

Docker Machine*

Docker Swarm*

FIG Docker Compose*

Images

Docker Ecosystem

Images, Layers, Containers

Definition

  • Read-only or read-write file system

LAYER

  • Read-only LAYER
  • Can be a result of multiple (read-only) layers stacked on top of each other

IMAGE

  • Process launched based on an IMAGE
  • Add a read-write layer on top all read-only layers

CONTAINER

Base Image

bootfs

(bootloader, kernel)

rootfs

/dev, /proc, /bin, /etc, /lib, /usr, /tmp

{

Debian

Image

}

layer

layer

}

Stacked Layers

bootfs

Kernel

Debian

Base Image

CentOS

Base Image

Apache:80

Image

Nginx:80

Image

Writable FS

{

App

A

}

App

B

Writable FS

So far so good?

First steps with Docker

host-os $  docker search ubuntu

Search for a pre-built image

NAME           DESCRIPTION                             STARS      OFFICIAL       AUTOMATED

ubuntu         Official Ubuntu base image      1208         [OK]  

host-os $  docker pull ubuntu:latest

Download a pre-built image

host-os $  docker images

Listing available images

REPOSITORY    TAG                IMAGE ID                CREATED              VIRTUAL SIZE

ubuntu              latest              9bd07e480c5b        7 weeks ago         192.7 MB

host-os $  docker run -i -t ubuntu /bin/bash

Running an interactive shell

ubuntu $   _

host-os $  docker run -d ubuntu \

Starting a long-running worker process

/bin/sh -c "while true; do echo Hello World; sleep 1; done"

fd2827f60bf56d00e0ef21e711df153e05585f27a382bdccaced3dd51921e232

host-os $  _

host-os $  docker ps

Listing containers

CONTAINER ID       IMAGE                      COMMAND                       CREATED                  STATUS                   PORTS     NAMES
fd2827f60bf5    ubuntu:latest   "/bin/sh -c 'while t    9 minutes ago   Up 8 minutes                blue_sky  

host-os $  docker ps -a

CONTAINER ID       IMAGE                      COMMAND                       CREATED                  STATUS                   PORTS     NAMES
fd2827f60bf5    ubuntu:latest   "/bin/sh -c 'while t    9 minutes ago   Up 8 minutes                blue_sky  

7f60ad3fabf5    ubuntu:latest   "/bin/sh -c 'while t    9 minutes ago   Exited (-1)  6s                red_sea  

Controlling containers

host-os $  docker stop  blue_sky

STOP

host-os $  docker start  blue_sky

START

host-os $  docker stop  blue_sky

host-os $  docker rm  blue_sky

REMOVE

Committing (saving) a container state

host-os $  docker commit blue_sky sky_img

host-os $  docker images

REPOSITORY    TAG                IMAGE ID                CREATED              VIRTUAL SIZE

sky_img              latest              e480abcedc3b        5 seconds  ago   192.7 MB

host-os $  docker --help

Complete Reference

  • attach
  • build
  • commit
  • cp
  • create
  • diff
  • events
  • exec
  • export
  • history
  • images
  • import
  • info
  • inspect
  • kill
  • load
  • login
  • logout
  • logs
  • port
  • pause
  • ps
  • pull
  • restart
  • rm
  • rmi
  • run
  • save
  • search
  • start
  • stop

...and more...

Dockerfiles

Docker can build images automatically by reading the instructions from a Dockerfile.

A Dockerfile is a text document that contains all the commands you would normally execute manually in order to build a Docker image. 

By calling docker build from your terminal, you can have Docker build your image step by step, executing the instructions successively.

Sample Dockerfile

FROM buildpack-deps:sid-curl

RUN apt-get update && apt-get install -y unzip \
    && rm -rf /var/lib/apt/lists/*

ENV JAVA_VERSION 8u40~b22
ENV JAVA_DEBIAN_VERSION 8u40~b22-2

ENV CA_CERTIFICATES_JAVA_VERSION 20140324

RUN apt-get update && apt-get install -y \
        openjdk-8-jre-headless="$JAVA_DEBIAN_VERSION" \
        ca-certificates-java="$CA_CERTIFICATES_JAVA_VERSION" \
    && rm -rf /var/lib/apt/lists/*

RUN /var/lib/dpkg/info/ca-certificates-java.postinst configure

Building an Image

host-os $  docker build -t openjdk-8-jre .

Uploading context 10.24 kB
Uploading context

Step 1 : FROM buildpack-deps:sid-curl
---> cbba202fe96b

Step 2 : RUN apt-get update && apt-get install -y unzip && rm -rf /var/lib/apt/lists/*
---> 51182097be13

...

Step 7 : RUN /var/lib/dpkg/info/ca-certificates-java.postinst configure

Successfully built 1a5ffc17324d

Demo

Questions ?

Thank You!

Made with Slides.com