Intro to Docker

Contain yourselves

Who am I ?

Joshua Burke

Teacher and Mentor

Meetup Organizer

Ruby Developer

Part-time DevOps

Not a SysAdmin

What is Docker ?

Docker allows you to package an application with all of it's dependencies into a standard unit.

Vagrant vs. Docker

VM Manager

Container Manager

What is a container?

How are containers

different ?

Start time                                         ( seconds v.s. minutes )

Server resources                            ( 128MB v.s. 1GB RAM )

Consistency                               ( no more "works for me" )

Smaller Package Size                ( 100-1000MB vs. 3-5 GB )

Idempotent  builds                ( same instructions always )

Isolation of dependencies      ( Redis/MySQL in Docker )

Easy to share containers      ( docker pull image_name )

Docker Architecture

The big picture

Docker Architecture

   OSX              ||         Linux           ||         Windows

Docker Friends

Engine || Machine || Compose || Registry || Swarm

Docker Engine

Primary runtime

# run an some_container and shut it down after exit

$ docker run -it some_container some_command

# list all the containers available within local docker host

$ docker ps -a 
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                      PORTS               NAMES
ee51d10253ae        ubuntu              "bash"              30 minutes ago      Exited (0) 17 seconds ago                       jolly_jones
1f7f1f55c9e2        hello-world         "/hello"            32 minutes ago      Exited (0) 32 minutes ago                       gloomy_kirch

Docker Machine

Create and manage the VM running Docker

$ docker-machine create --driver virtualbox demo

Running pre-create checks...
Creating machine...
(demo) Creating VirtualBox VM...
(demo) Creating SSH key...
(demo) Starting VM...
Waiting for machine to be running, this may take a few minutes...
Machine is running, waiting for SSH to be available...
Detecting operating system of created instance...
Detecting the provisioner...
Provisioning with boot2docker...
Copying certs to the local machine directory...
Copying certs to the remote machine...
Setting Docker configuration on the remote daemon...
Checking connection to Docker...
Docker is up and running!
To see how to connect Docker to this machine, run: docker-machine env demo

Docker Machine

Create and manage the VM running Docker

$ docker-machine start demo

$ eval "$(docker-machine env demo)"

$ env | grep DOCK
DOCKER_TLS_VERIFY=1
DOCKER_HOST=tcp://192.168.99.100:2376
DOCKER_CERT_PATH=/Users/mansfield/.docker/machine/machines/demo
DOCKER_MACHINE_NAME=demo

Docker Files

# start with the official Ruby image
FROM ruby:2.2.3

# update and get a C compiler
RUN apt-get update -qq && apt-get install -y build-essential

# postgres
RUN apt-get intall -y libpq-dev

# nokogiri
RUN apt-get install -y libxml2-dev libxslt1-dev nodejs

# setup the directory for the app
ENV APP_HOME /app/demo
RUN mkdir -p $APP_HOME
WORKDIR $APP_HOME

# install the gems with bundler
ADD Gemfile $APP_HOME/Gemfile
ADD Gemfile.lock $APP_HOME/Gemfile.lock
RUN bundle install --jobs=4

# check for and remove a server pid
RUN test -f $APP_HOME/tmp/pids/server.pid && \
    rf $APP_HOME/tmp/pids/server.pid; true

ADD . $APP_HOME

Docker Compose

Configures ports, env, and links between containers

# docker-compose.yml within the project directory
db:
  image: postgres:9.4.1
  ports:
    - "5432:5432"
web:
  build: .
  command: bundle exec rails s -p 3000 -b '0.0.0.0'
  ports:
    - "3000:3000"
  links:
    - db
  volumes:
    - .:/app/demo

docker-compose.yml

Docker-compose CLI

Docker Compose

Configures ports, env, and links between containers

# from within same dir as docker-compose.yml

$ docker-compose build

db uses an image, skipping
Building web
Step 1 : FROM ruby:2.2.3
 ---> 72336174e973
Step 2 : RUN apt-get update -qq && apt-get install -y build-essential
 ---> Using cache
 ---> 228e9f49e57d ...

$ docker-compose up

Pulling image redis...
Building web...
Starting composetest_redis_1...
Starting composetest_web_1...
redis_1 | [8] 02 Jan 18:43:35.576
web_1   |  * Running on http://0.0.0.0:5000/
web_1   |  * Restarting with stat

Docker-compose CLI

Docker Registry (Hub)

Store private or use open source containers 

Docker Swarm

Setup and manage a cluster of hosts

Demo

Live ... maybe

What is next?

Mesosphere

Kubernetes

CoreOS

Rancher

Tutum

Others

Resources

Made with Slides.com