Docker 101 
An Introduction to Containerizing Apps 
Benjamin Schmidt 
kWantera.com CTO
Agenda 
● What is Docker? 
● Using Docker 
● What can you do with Docker? 
● Examples 
● Tech that extends Docker
Talk’s Purpose 
● While simple, Docker is expansive in it’s 
capabilities 
● I’d like to cover enough so people can 
understand the concepts 
● I leave it to the docs and SO for becoming 
“experts”
What is Docker? 
“open platform … to build, ship and run 
distributed applications” 
Linux virtualization made easy (and light-weight)
A Container For Your App 
● You’ve got code 
● Docker is a self-contained, customizable 
linux environment to run that code 
● It is a virtual machine without the full OS
Origins (-ish) 
● Linux containers (LXC) :: sort of like chroot 
● Create a kernel separated environment for 
security purposes 
● Since it’s part of kernel = does not require a 
full OS 
● Can run multiple containers on same system 
● Sprinkle in resource constraints 
● Add a dash of environment scripting
Representation 
You have an “App” you want 
to run: 
● Mongo server 
● HTTP server 
● Long-running script 
● An ad-hoc backup script 
image source: docker.io
Representation 
Traditionally you run it on a 
“full server” 
image source: docker.io 
Required 
libraries 
The physical 
hardware
Representation 
Virtualization solved the 
multiple-app / library 
problem 
● Still a single physical hardware server 
image source: docker.io 
Use Virtualization to 
mirror the “physical” 
hardware at OS level
Representation 
Some inefficiencies pop-up 
● Architecture duplication 
● Setting up “fully systems” 
=> Leads to resource waste 
image source: docker.io 
HEAVY copying & 
redundancy 
Potentially 
redundant
Representation 
Docker Solution 
● There is only one running “full OS” 
o You use a dedicated portion of kernel 
resources 
● Much lighter weight leads to: 
o Easily cloneable containers 
o Sharing system libraries versus program 
libraries (i.e. a portion of the host kernel) 
image source: docker.io
Terminology 
● Container 
o Runs your code using a specified environment 
(Image) and the command you wish to execute in 
that environment 
● Image 
o An environment complete with the type of OS and 
any setup instructions for generating that 
environment
Using Docker 
● Docker has a pretty simple command line 
API* 
o run: converts images and commands into containers 
o start/stop: starts or stops containers 
o ps: inspect the available containers and their status 
o images: list all available images (locally 
downloaded) 
o build: builds image (e.x from a Dockerfile) 
*Other commands exist for more fine-grained control and inspection
At this point... 
● I want to give a flavor for Docker usage 
without all the details 
o See the Docs for extensive coverage 
o This is just a 101 course :)
Let’s start a docker container... 
$ sudo docker run ubuntu:14.04 /bin/echo ‘Hello World’ 
Hello World
Let’s start a docker container... 
Accesses LXC 
under the hood 
(needs root) 
The type of 
Image 
Convert from 
Image to 
Container 
The command to 
run in that image 
type 
$ sudo docker run ubuntu:14.04 /bin/echo ‘Hello World’ 
Hello World
And if you wanted to test in multiple 
OS’s... 
$ sudo docker run ubuntu:14.04 /bin/echo ‘Hello World’ 
Hello World 
$ sudo docker run ubuntu /bin/echo ‘Hello World’ 
Hello World 
$ sudo docker run centos /bin/echo ‘Hello World’ 
Hello World 
$ sudo docker run debian /bin/echo ‘Hello World’ 
Hello World
A few notes 
● Program printed to STDOUT (the console) 
● If you run `sudo docker ps` you won’t see 
any currently running containers (it stopped) 
● Running `sudo docker ps -a` will show a 
stopped container
And if you want an interactive shell... 
$ sudo docker run -t -i ubuntu:14.04 /bin/bash 
root@ae23f43: | 
-t = pseudo-tty 
terminal 
-i = interactive (STDIN is 
piped into process)
And if you want an interactive shell... 
$ sudo docker run -t -i ubuntu:14.04 /bin/bash 
root@ae23f43: | 
And to know you’re not in a full OS, try 
`top`... only two processes
And throw a process into 
background... 
$ sudo docker run -d ubuntu /bin/sh -c "while true; do echo hello world; sleep 1; 
done" 
1e5535038e285177d5214659a068137486f96ee5c2e85a4ac52dc83f2ebe4147 
-d = daemonize 
leaving off :14.04 provides 
the “latest” version 
Returns the 
container ID
Bind ports inside container to host... 
$ sudo docker run -d -p 5000:5000 ubuntu python myserver.py 
-p = port mapping. 
(lower case) 
Inside:Outside
Dockerfile 
Create Images # Put this in a file called Dockerfile 
FROM ubuntu 
MAINTAINER Ben Schmidt <ben@example.com> 
RUN apt-get update 
$ cd ~/myserver 
$ sudo docker build -t=”myimage” . 
$ sudo docker run -i -it myimage /bin/bash 
A Dockerfile in ~/myimage/ 
-t = Set the name of the 
image
Things to be Aware of... 
● Containers run in their own environment 
o Files, ports, and host data must be “mapped” to the 
container 
o EXPOSE: exposes ports to host 
o ADD: copies local host files into container 
● Volumes allow exposure of host OS 
filesystem to containers 
o Can get very tricky! But allows shared storage and 
even containers that act as storage only
Things to be Aware of... 
● Images are stored with a VCS-ish 
o Each line in a Dockerfile creates a new image 
o FROM command allows stacking of images 
o Can create parent-child relationships 
o sudo docker commit or pull 
● Docker Hub 
o Store your images in the cloud 
o This is default how we access many of the common 
images (ubuntu, centos etc.) 
o Can also create your own private repository
Things to be Aware of... 
● Resource limits 
o Can set CPU and RAM limits 
● Networking 
o Docker creates an elaborate networking 
infrastructure via clever use of /etc/hosts 
o Do not modify /etc/hosts!! or do so at peril
Neat tech out there today... 
Docker swarm: 
https://github.com/docker/swarm 
CoreOS Rocket: 
https://github.com/coreos/rocket
Thanks!! 
Contact: 
Ben Schmidt 
kwantera.com

Docker 101

  • 1.
    Docker 101 AnIntroduction to Containerizing Apps Benjamin Schmidt kWantera.com CTO
  • 2.
    Agenda ● Whatis Docker? ● Using Docker ● What can you do with Docker? ● Examples ● Tech that extends Docker
  • 3.
    Talk’s Purpose ●While simple, Docker is expansive in it’s capabilities ● I’d like to cover enough so people can understand the concepts ● I leave it to the docs and SO for becoming “experts”
  • 4.
    What is Docker? “open platform … to build, ship and run distributed applications” Linux virtualization made easy (and light-weight)
  • 5.
    A Container ForYour App ● You’ve got code ● Docker is a self-contained, customizable linux environment to run that code ● It is a virtual machine without the full OS
  • 6.
    Origins (-ish) ●Linux containers (LXC) :: sort of like chroot ● Create a kernel separated environment for security purposes ● Since it’s part of kernel = does not require a full OS ● Can run multiple containers on same system ● Sprinkle in resource constraints ● Add a dash of environment scripting
  • 7.
    Representation You havean “App” you want to run: ● Mongo server ● HTTP server ● Long-running script ● An ad-hoc backup script image source: docker.io
  • 8.
    Representation Traditionally yourun it on a “full server” image source: docker.io Required libraries The physical hardware
  • 9.
    Representation Virtualization solvedthe multiple-app / library problem ● Still a single physical hardware server image source: docker.io Use Virtualization to mirror the “physical” hardware at OS level
  • 10.
    Representation Some inefficienciespop-up ● Architecture duplication ● Setting up “fully systems” => Leads to resource waste image source: docker.io HEAVY copying & redundancy Potentially redundant
  • 11.
    Representation Docker Solution ● There is only one running “full OS” o You use a dedicated portion of kernel resources ● Much lighter weight leads to: o Easily cloneable containers o Sharing system libraries versus program libraries (i.e. a portion of the host kernel) image source: docker.io
  • 12.
    Terminology ● Container o Runs your code using a specified environment (Image) and the command you wish to execute in that environment ● Image o An environment complete with the type of OS and any setup instructions for generating that environment
  • 13.
    Using Docker ●Docker has a pretty simple command line API* o run: converts images and commands into containers o start/stop: starts or stops containers o ps: inspect the available containers and their status o images: list all available images (locally downloaded) o build: builds image (e.x from a Dockerfile) *Other commands exist for more fine-grained control and inspection
  • 14.
    At this point... ● I want to give a flavor for Docker usage without all the details o See the Docs for extensive coverage o This is just a 101 course :)
  • 15.
    Let’s start adocker container... $ sudo docker run ubuntu:14.04 /bin/echo ‘Hello World’ Hello World
  • 16.
    Let’s start adocker container... Accesses LXC under the hood (needs root) The type of Image Convert from Image to Container The command to run in that image type $ sudo docker run ubuntu:14.04 /bin/echo ‘Hello World’ Hello World
  • 17.
    And if youwanted to test in multiple OS’s... $ sudo docker run ubuntu:14.04 /bin/echo ‘Hello World’ Hello World $ sudo docker run ubuntu /bin/echo ‘Hello World’ Hello World $ sudo docker run centos /bin/echo ‘Hello World’ Hello World $ sudo docker run debian /bin/echo ‘Hello World’ Hello World
  • 18.
    A few notes ● Program printed to STDOUT (the console) ● If you run `sudo docker ps` you won’t see any currently running containers (it stopped) ● Running `sudo docker ps -a` will show a stopped container
  • 19.
    And if youwant an interactive shell... $ sudo docker run -t -i ubuntu:14.04 /bin/bash root@ae23f43: | -t = pseudo-tty terminal -i = interactive (STDIN is piped into process)
  • 20.
    And if youwant an interactive shell... $ sudo docker run -t -i ubuntu:14.04 /bin/bash root@ae23f43: | And to know you’re not in a full OS, try `top`... only two processes
  • 21.
    And throw aprocess into background... $ sudo docker run -d ubuntu /bin/sh -c "while true; do echo hello world; sleep 1; done" 1e5535038e285177d5214659a068137486f96ee5c2e85a4ac52dc83f2ebe4147 -d = daemonize leaving off :14.04 provides the “latest” version Returns the container ID
  • 22.
    Bind ports insidecontainer to host... $ sudo docker run -d -p 5000:5000 ubuntu python myserver.py -p = port mapping. (lower case) Inside:Outside
  • 23.
    Dockerfile Create Images# Put this in a file called Dockerfile FROM ubuntu MAINTAINER Ben Schmidt <ben@example.com> RUN apt-get update $ cd ~/myserver $ sudo docker build -t=”myimage” . $ sudo docker run -i -it myimage /bin/bash A Dockerfile in ~/myimage/ -t = Set the name of the image
  • 24.
    Things to beAware of... ● Containers run in their own environment o Files, ports, and host data must be “mapped” to the container o EXPOSE: exposes ports to host o ADD: copies local host files into container ● Volumes allow exposure of host OS filesystem to containers o Can get very tricky! But allows shared storage and even containers that act as storage only
  • 25.
    Things to beAware of... ● Images are stored with a VCS-ish o Each line in a Dockerfile creates a new image o FROM command allows stacking of images o Can create parent-child relationships o sudo docker commit or pull ● Docker Hub o Store your images in the cloud o This is default how we access many of the common images (ubuntu, centos etc.) o Can also create your own private repository
  • 26.
    Things to beAware of... ● Resource limits o Can set CPU and RAM limits ● Networking o Docker creates an elaborate networking infrastructure via clever use of /etc/hosts o Do not modify /etc/hosts!! or do so at peril
  • 27.
    Neat tech outthere today... Docker swarm: https://github.com/docker/swarm CoreOS Rocket: https://github.com/coreos/rocket
  • 28.
    Thanks!! Contact: BenSchmidt kwantera.com