Docker 101
-
Upload
schmidtbt -
Category
Technology
-
view
113 -
download
0
Transcript of Docker 101
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
The physical
hardware
Required
libraries
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
● Containero Runs your code using a specified environment
(Image) and the command you wish to execute in
that environment
● Imageo 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 detailso 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...
$ sudo docker run ubuntu:14.04 /bin/echo ‘Hello World’
Hello World
Accesses LXC
under the hood
(needs root)
Convert from
Image to
Container
The type of
ImageThe command to
run in that image
type
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
DockerfileCreate Images
# Put this in a file called Dockerfile
FROM ubuntu
MAINTAINER Ben Schmidt <[email protected]>
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 environmento 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-isho 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 Hubo 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 limitso Can set CPU and RAM limits
● Networkingo 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