Introduction to Docker

An open platform for distributed applications for developers and sysadmins

by Brian DeRocher / @openbrian

2015 October 27

Dock What?!

Docker is a container which developers build around their applications in order to ship them into operating environments such as the cloud.

https://www.docker.com/

Executive Summary

  • Reduce uncertainty when building and deploying software
  • Standardize your deployments
  • Deploy more often without anxiety
  • Reap value of new features earlier
  • Integrate with the cloud
    • AWS Elastic Beanstalk
    • Google Container Engine
    • Joyent, IBM Softlayer, Microsoft Azure, Rackspace

Have you ever had these issues?

  • App works in Dev but not in Prod. Why?
  • As a developer, your new project depends on Python 2.3, but previous project depends on Python 2.2
  • Developer says "Please deploy on Apache 2.2". Sysadmin deploys to "more secure" Apache 2.4
  • Developer says "Deploy on Ubuntu, Nginx, Memcache, Oracle, libgd, libcrypt...., and put this file here". Sysadmin says "no".
  • Push to build server (CI), QA server, local network (dogfood), public cloud, mobile, on premise

Solution: Docker

  • Isolated environment from other projects
  • Consistent environment across developers
  • Consistent environment from dev to ops
  • Image contains all dependencies

Context

  • build environment, like Python's virtualenv
  • 1982 - chroot , bsd jails - filesystem protection only
  • LXC adds userspace isolotion
  • Docker - cgroups
  • virtual machine
  • Vagrant

Docker: In a Nutshell

Daemon Images Containers Hub

See also: Kitematic

Daemon


$ apt-get install docker

Images

Pull pre-existing imags from the Hub


$ docker pull django
django

Build images from a Dockerfile


$ docker build -t noblis/grailsapp .

List your docker images


$ docker images

Containers

Start an independent container from an image


$ docker run -it -p 3000:80 -V /home/amr/app:/opt noblis/grailsapp

List the running and non-running containers


$ docker ps -a

Save container changes as a new image


$ docker commit CONTAINER_ID noblis/grailsapp:version3

Hub

Publish new images on the Docker Hub


$ apt-get push

Docker Link

Each docker container may EXPOSE ports. "Linking" will bridge the port from one container to a port on another. For example EXPOSE 5432 PostgreSQL database with tag db. On web container use


docker run --name web --link db:thedb noblis/webapp python app.py

Then web container has environment variables defiend THEDB_NAME, THEDB_HOST, THEDB_PORT. And in the web app configuration connect to tcp://$THEDB_HOST:$THEDB_PORT/$THEDB_NAME.

Demo

Questions?

Brian DeRocher

@openbrian