Intro to Docker

Daniel Farrell
Red Hat SDN Team

VERY QUICK: INTRO TO ME

Daniel Farrell
Software Engineer, Red Hat SDN Team

VERY QUICK: INTRO TO ME

OpenDaylight Contributor

VERY QUICK: INTRO TO ME

OpenDaylight Integration Committer


Very Quick: Intro to ME

Other code!
 

VERY QUICK: INTRO TO ME

Robots!
 

VERY QUICK: INTRO TO ME

(Craft) Beer!

VERY QUICK: INTRO TO ME

Biking!

VERY QUICK: INTRO TO ME

SCUBA!

Goal

Very practical intro to using Docker

Overview

OVERVIEW

Lightweight, very fast containers

OVERVIEW

Consistent across dev,  QA, production...

OVERVIEW

Deploy anywhere

OVERVIEW

Horizontal scaling

OVERVIEW

Layered file system -> huge wins

OVERVIEW

No hypervisor, so speed/isolation trade-off

OVERVIEW

Dockerfile -> docs and version control

LXC vs Docker

LXC VS DOCKER

Docker foundations have been in kernel for years

LXC VS DOCKER

LXC: sandboxing processes; controlling resource allocation

LXC VS DOCKER

Docker adds:
Portable deployments

LXC VS DOCKER

Docker adds:
Git-like versioning

LXC VS DOCKER

Docker adds:
"Base images"

LXC VS DOCKER

Docker adds:
Application-centric

LXC VS DOCKER

~Docker adds:
DockerHub

Dockerfiles

DOCKERFILES

Build from a base image
# Base the image on Debian 7
# Picked Debian because it's small (85MB)
# https://registry.hub.docker.com/_/debian/
FROM debian:7

DOCKERFILES

RUN cmds to customize
# Install required software (170MB)
RUN apt-get update && apt-get install -y openjdk-7-jre-headless wget

DOCKERFILES

You can set the CWD
WORKDIR /opt

DOCKERFILES

You can expose ports
EXPOSE 162 179 1088 1790 1830 2400 2550 2551 2552 4189 4342 5005 5666 6633 6640 6653 7800 8000 8080 8101 8181 8383 12001

DOCKERFILES

Drop your project in the container with ADD
# Drop source (bot2014, current context) in /opt dir 
# Do the ADD as late as possible, as it invalidates cache 
ADD . /opt/bot

DOCKERFILES

Default process execution for container with CMD
CMD ["./bin/karaf", "server"]

FS Layers

FS Layers

Docker uses a layered file system

FS LAYERS

Stack of RO layers with a RW layer on top

FS LAYERS

If nothing has changed about lower layers...

FS LAYERS

Caching! Speed! *Wins*!

FS LAYERS

[~/foss_rocks]$ time docker build -t dfarrell07/preanalytics:dev .
Sending build context to Docker daemon   343 kB
Step 0 : FROM debian:8.0
 ---> 835c4d274060
# Snip
Step 3 : ADD requirements.txt /tmp/requirements.txt
 ---> Using cache
 ---> 905a16f73f42
Step 4 : RUN pip install -r /tmp/requirements.txt
 ---> Using cache
 ---> f0af2258d85b
# Snip
Successfully built d3b3424b1313
docker build -t dfarrell07/preanalytics:dev .  0.01s user 0.01s system 7% cpu

FS Layers

Term: Images
Step 6 : WORKDIR /opt/preanalytics
 ---> Using cache
 ---> d3b3424b1313
Successfully built d3b3424b1313

FS Layers

Term: Container
(overloaded)
1. The read/write layer on top
2. A running Docker thing

BUILDING IMAGES

Building Images

docker build [-t tag name] .

Building Images

docker build -t dfarrell07/opendaylight:dev .

BUILDING IMAGES


[~]$ docker images | tail -n 5
debian                    8.0                 835c4d274060        5 weeks ago         122.6 MB
debian                    jessie              835c4d274060        5 weeks ago         122.6 MB
fedora                    21                  834629358fe2        5 weeks ago         250.2 MB
fedora                    latest              834629358fe2        5 weeks ago         250.2 MB
dfarrell07/helium         dev                 e5ece2a3040a        7 weeks ago         537.3 MB

Running containers

RUNNING CONTAINERS

[~]$ docker run -ti dfarrell07/helium:dev bash
root@97aec28eae4d:/opt/opendaylight#

RUNNING CONTAINERS

[~]$ docker run -ti dfarrell07/preanalytics:dev tox
# snip
Ran 160 tests in 26.513s

OK (skipped=4)

RUNNING CONTAINERS

[~/preanalytics]$ docker ps
CONTAINER ID        IMAGE                         COMMAND                CREATED             STATUS              PORTS                                                                                                                                                                                                                                 NAMES
bb6450f64015        dfarrell07/preanalytics:dev   "bash"                 26 minutes ago      Up 26 minutes                                                                                                                                                                                                                                             condescending_bell

Other Resources

Contact

Daniel Farrell
Twitter (optimal):

Others:
dfarrell@redhat.com
dfarrell07 on IRC, GitHub

Introduction to Docker

By Daniel Farrell

Introduction to Docker

Talk given at the NCSU LUG's 2015 FOSS Fair

  • 2,413