Docker

Download as pdf or txt
Download as pdf or txt
You are on page 1of 45

Introduction to Docker

Contents
Introduction to Containers
What is Docker?
Docker Architecture
Installing Docker
Docker Engine
Docker Images
Docker File
Docker Hub
Docker CLI
Kubernetes
Hands On Demo
Containers
LXC (Linux Containers) is an operating-system-level
virtualization method for running multiple isolated Linux
systems (containers) on a control host using a single Linux
kernel.

The Linux kernel provides the cgroups functionality that


allows limitation and prioritization of resources (CPU,
memory, block I/O, network, etc.) without the need for
starting any virtual machines, and namespace isolation
functionality that allows complete isolation of an
applications' view of the operating environment, including
process trees, networking, user IDs and mounted file
systems
Why Containers
What is Docker
Docker is an open-source project that automates the
deployment of applications inside software container
Docker containers wrap up a piece of software in a
complete file system that contains everything it needs to
run: code, runtime, system tools, system libraries
anything you can install on a server.
This guarantees that it will always run the same,
regardless of the environment it is running in.
The Challenge

User DB

Do services and
appropriately?
Static website

apps interact
postgresql + pgv8 + v8
Queue Analytics DB
Multiplicity of

nginx 1.5 + modsecurity + openssl + bootstrap 2 hadoop + hive + thrift + OpenJDK


Stacks

Redis + redis-sentinel

Web frontend
Background workers
Ruby + Rails + sass + Unicorn
Python 3.0 + celery + pyredis + libcurl + ffmpeg + libopencv + nodejs +
phantomjs API endpoint
Python 2.7 + Flask + pyredis + celery + psycopg + postgresql-client

Production Cluster
Development VM
environments
Multiplicity of

Public Cloud
hardware

smoothly and
Can I migrate
quickly?
QA server
Disaster recovery
Customer Data Center Contributors laptop
Production Servers
The Matrix From Hell
Static website ? ? ? ? ? ? ?

Web frontend ? ? ? ? ? ? ?

Background workers ? ? ? ? ? ? ?

User DB ? ? ? ? ? ? ?

Analytics DB ? ? ? ? ? ? ?

Queue ? ? ? ? ? ? ?

Development Single Prod Onsite Contributors Customer


QA Server Public Cloud
VM Server Cluster laptop Servers
Do I worry about Can I transport
how goods interact quickly and smoothly
(e.g. coffee beans (e.g. from boat to
next to spices) train to truck)
Cargo Transport Pre-1960
g
Goods transporting/storin
Multiplicity of methods for
Multipilicity of
Also a matrix from hell

? ? ? ? ? ? ?

? ? ? ? ? ? ?

? ? ? ? ? ? ?

? ? ? ? ? ? ?

? ? ? ? ? ? ?

? ? ? ? ? ? ?
Solution: Intermodal Shipping Container

how goods interact


(e.g. coffee beans

Do I worry about
next to spices)
Multiplicity of
Goods

A standard container that is


loaded with virtually any goods,
and stays sealed until it reaches
final delivery.

in between, can be loaded and


unloaded, stacked, transported
efficiently over long distances, and
transporting/stori

(e.g. from boat to

Can I transport
transferred from one mode of

train to truck)
Multiplicity of
methods for

quickly and
transport to another

smoothly
ng
Docker is a shipping container system for
code
Static website User DB Web frontend Queue Analytics DB

Do services and
appropriately?
apps interact
Multiplicity of
Stacks

An engine that enables any


payload to be encapsulated as
a lightweight, portable, self-
sufficient container

that can be manipulated using


standard operations and run
environments
Multiplicity of

consistently on virtually any


hardware

smoothly and
Can I migrate
hardware platform

quickly
Development QA server Customer Data Public Cloud Production Contributors
VM Center Cluster laptop
Docker eliminates the matrix from Hell
Static website

Web frontend

Background workers

User DB

Analytics DB

Queue

Development Single Prod Onsite Contributors Customer


QA Server Public Cloud
VM Server Cluster laptop Servers
Why Developers Care
Build once, run anywhere

A clean, safe, hygienic and portable runtime


environment for your app.

No worries about missing dependencies, packages and


other pain points during subsequent deployments.

Run each app in its own isolated container, so you can


run various versions of libraries and other
dependencies for each app without worrying
Why Developers Care

Automate testing, integration, packaginganything


you can script

Reduce/eliminate concerns about compatibility on


different platforms, either your own or your customers.

Cheap, zero-penalty containers to deploy services? A


VM without the overhead of a VM? Instant replay and
reset of image snapshots? Thats the power of Docker
Why Devops Cares?

Configure oncerun anything

Make the entire lifecycle more efficient, consistent, and


repeatable

Increase the quality of code produced by developers.

Eliminate inconsistencies between development, test,


production, and customer environments
Why Devops Cares?

Support segregation of duties

Significantly improves the speed and reliability of


continuous deployment and continuous integration
systems

Because the containers are so lightweight, address


significant performance, costs, deployment, and
portability issues normally associated with VMs
Why it worksseparation of concerns

The Developer The Administrator


Worries about Worries about
whats inside the whats outside
container the container
His code
Logging
His Libraries
Remote access
His Package
Monitoring
Manager
Network config
His Apps
His Data All containers
start, stop, copy,
All Linux servers attach, migrate,
look the same etc. the same way
More technical explanation
WHY WHAT
Run everywhere High LevelIts a lightweight
Regardless of kernel VM
version (2.6.32+) Own process space
Regardless of host distro Own network interface
Physical or virtual, cloud Can run stuff as root
or not Can have its own /sbin/init
Container and host (different from host)
architecture must
match*
Run anything Low LevelIts chroot on steroids
If it can run on the host, Can also not have its own /sbin/init
it can run in the Container=isolated processes
container Share kernel with host
i.e. if it can run on a Linux No device emulation (neither HVM
kernel, it can run nor PV) from host)
Containers vs. VMs
Containers are isolated,
App App App but share OS and, where
A A B
appropriate,
Bins/ Bins/
Libs
Bins/ bins/libraries
Libs Libs
VM result is significantly faster
Guest Guest
OS OS deployment, much less overhead,
Guest Guest Guest easier migration, faster restart
OS OS OS

App A

App B

App B
App B
App A

App B

Docker
Container
Hypervisor (Type 2)
Bins/Libs Bins/Libs

Host OS Host OS
Server Server
Why are Docker containers lightweight?
VMs Containers
App App

App
App
App App A A A
A A
Bins/

Bins
Bins/ Bins/ Bins/

/
Libs Libs Libs Libs

Guest
OS
Guest Guest Guest Original App Copy of Modified App
OS OS OS (No OS to take App
up space, resources, No OS. Can Copy on write
or require restart) Share bins/libs capabilities allow
us to only save the
diffs
Between container
VMs A and container
Every app, every copy of an A
app, and every slight modification
of the app requires a new virtual server
What are the basics of the Docker system?

Push

Container A
Docker
Container
Image
Registry

Search Pull

Run
Build
Dockerfile
For
A

Container B
Container A

Container C

Docker
Source
Code
Repository Docker Engine

Host 1 OS (Linux)
Host 2 OS (Linux)
Changes and Updates

App Push

App
A
Docker
Bins/ Container

Bins
Libs Image

/
Registry

Base Container Container

App
Container Mod A Mod A
Image Update

Bins
/
App
App
A
A
Bins/
Bins/
Bins

Libs
/

Libs
Docker Engine
Docker Engine
Host is now running A Host running A wants to upgrade to A.
Requests update. Gets only diffs
Ecosystem Support
Operating systems
Virtually any distribution with a 2.6.32+ kernel
Red Hat/Docker collaboration to make work across
RHEL 6.4+, Fedora, and other members of the
family (2.6.32 +)
CoreOSSmall core OS purpose built with Docker
OpenStack
Docker integration into NOVA (& compatibility with
Glance, Horizon, etc.) accepted for Havana release
Private PaaS
OpenShift
Solum (Rackspace, OpenStack)
Other TBA
Public PaaS
Deis, Voxoz, Cocaine (Yandex), Baidu PaaS
Ecosystem Support
Public IaaS
Native support in Rackspace, Digital Ocean,+++
AMI (or equivalent) available for AWS & other
DevOps Tools
Integrations with Chef, Puppet, Jenkins, Travis,
Salt, Ansible +++
Orchestration tools
Mesos, Heat, ++
Shipyard & others purpose built for Docker
Applications
1000s of Dockerized applications available at
index.docker.io
Use Cases
Use Case Examples

Building a MongoDB cluster using docker

Clusters Production Quality MongoDB Setup with Docker

Wildfly cluster using Docker on Fedora

Build your own PaaS OpenSource PaaS built on Docker, Chef, and Heroku
Buildpacks

Web Based Environment for Instruction JiffyLab web based environment for the instruction, or
lightweight use of, Python and UNIX shell

Deploy Java Apps With Docker = Awesome

Easy Application Deployment How to put your development environment on docker

Running Drupal on Docker

Installing Wordpress on Docker


Use Cases
Use Case Examples

Create Secure Sandboxes Docker makes creating secure sandboxes easier than ever

Create your own SaaS Memcached as a Service

Automated Application Deployment Multi-cloud Deployment with Docker

Next Generation Continuous Integration & Deployment


with dotClouds Docker and Strider
Continuous Integration and Deployment
Testing Salt States Rapidly With Docker

Docker Desktop: Your Desktop Over SSH Running Inside


Lightweight Desktop Virtualization Of A Docker Container
Docker Architecture
Namespaces
Docker takes advantage of a technology called namespaces to
provide the isolated workspace we call the container.
When you run a container, Docker creates a set of namespaces for
that container.
Some of the namespaces that Docker Engine uses on Linux are:
1. The pid namespace: Process isolation (PID: Process ID).
2. The net namespace: Managing network interfaces (NET:
Networking).
3. The ipc namespace: Managing access to IPC resources (IPC:
InterProcess Communication).
4. The mnt namespace: Managing mount-points (MNT: Mount).
5. The uts namespace: Isolating kernel and version identifiers. (UTS:
Unix Timesharing System)
Control groups
Docker Engine on Linux also makes use of another
technology called cgroups or control groups.
A key to running applications in isolation is to have them
only use the resources you want.
This ensures containers are good multi-tenant citizens on
a host.
Control groups allow Docker Engine to share available
hardware resources to containers and, if required, set up
limits and constraints.
For example, limiting the memory available to a specific
container.
Docker Architecture
Docker Engine
Docker Engine is a client-server application with these
major components:

A server which is a type of long-running program called a


daemon process.

A REST API which specifies interfaces that programs can


use to talk to the daemon and instruct it what to do.

A command line interface (CLI) client.


Docker Engine
Docker images
A Docker image is a read-only template. For example, an
image could contain an Ubuntu operating system with
Apache and your web application installed.

Images are used to create Docker containers. Docker


provides a simple way to build new images or update
existing images, or you can download Docker images that
other people have already created.

Docker images are the build component of Docker.


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

A Dockerfile is a text document that contains all the


commands a user could call on the command line to assemble
an image.

Using docker build users can create an automated build that


executes several command-line instructions in succession.

The docker build command builds an image from a Dockerfile


and a context.
Docker File - Example
Instructions
INSTRUCTION arguments
Eg. RUN echo 'we are running some # of cool things!
Parser directives:
FROM ImageName

Example:
#Comment
FROM windowsservercore
COPY testfile.txt c:\
RUN dir c:\

To Build image using this file:


docker build -f /path/to/a/Dockerfile .
Docker Hub
Docker registries hold images.
These are public or private stores from which you upload
or download images.
The public Docker registry is provided with the Docker
Hub. (hub.docker.com)
It serves a huge collection of existing images for your use.
These can be images you create yourself or you can use
images that others have previously created.
Docker registries are the distribution component of
Docker.
Docker CLI
The CLI makes use of the Docker REST API to control or
interact with the Docker daemon through scripting or
direct CLI commands.

Many other Docker applications make use of the


underlying API and CLI.

The CLI is also used to issue commands.


Kubernetes
Kubernetes is an open-source platform for
automating deployment, scaling, and
operations of application containers across
clusters of hosts, providing container-centric
infrastructure.

With Kubernetes, you can:


Deploy your applications quickly and predictably.
Scale your applications on the fly.
Seamlessly roll out new features.
Optimize use of your hardware by using only the
resources you need
Kubernetes Architecture
Kubernetes Features
Kubernetes is:
portable: public, private, hybrid, multi-cloud
extensible: modular, pluggable, hookable,
composable
self-healing: auto-placement, auto-restart,
auto-replication, auto-scaling

The Kubernetes project was started by Google


in 2014.
Demo Time!
Q&A
Thank you

You might also like