Skip to content
This repository has been archived by the owner on Oct 11, 2022. It is now read-only.

Latest commit

 

History

History
850 lines (802 loc) · 28.4 KB

workshop.org

File metadata and controls

850 lines (802 loc) · 28.4 KB

Student Preparation

Learning Goals

understand how docker works at a deep level

  • linux kernel containerization mechanisms
    • cgroups
    • namespaces
    • capabilities
  • Docker’s image layering & the various subsystems implementing it
  • container life-cyle
  • what build-files are doing
  • Docker’s networking / routing

understand docker.io’s ‘philosophy’ about Docker vs other approaches

understand how it compares to other options

understand its limitations and current gotchas

understand the variety of ways it can be used

build some muscle memory for core commands & use cases

be able to notice, diagnose and fix error conditions

know where look for details on a variety of related subjects

Morning 8-12

Setup & Intro & Overview (8 - 8:30)

name badges / github names on paper next to each computer

form 3 person teams & sit together

create a team channel on https://docker-in-depth.slack.com

validate ssh keypairs against ec2 vms

30sec round the room intros

Why do we care about Docker?

http://www.slideshare.net/BodenRussell/kvm-and-docker-lxc-benchmarking-with-openstack?ref=http://bodenr.blogspot.ca/2014/05/kvm-and-docker-lxc-benchmarking-with.html?utm_source=Docker+News&utm_campaign=7031cca54b-Docker_0_5_0_7_18_2013&utm_medium=email&utm_term=0_c0995b6e8f-7031cca54b-235743341

Example use cases:

  • Util packing
  • Dev tools in a box, host bind
  • Demo shipping
  • Production environments?
  • Supervisor systems inside of related set of docker container

Workshop Overview

  • focused on hands-on learning through exercises and exploration
  • guided exploration rather than lectures and canned tutorials

Installation

Base Ubuntu 14.04 Server LTS

btrfs

utils we’ll use

LXC

Docker

curl -s https://get.docker.io/ubuntu/ | sh apt-get install linux-image-extra-`uname -r` cat /proc/filesystems | grep aufs

update-grub && reboot

vs explicit manual install from packages (lxc-docker, not docker.io)

Foundations (8:30 - 9:30)

History elsewhere

  • containerization is an old concept, Linux late to the game

LXC

Google

https://github.com/google/lmctfy

lxc hello world

docker hello world

  • running a container in the foreground
  • running it in the background and inspecting the logs
  • running bash inside to inspect the env, network and file system

Exploring Linux kernel subsystems involved in each hello world example

more on cgroups http://www.slideshare.net/azilian/lsa2-02-cgroups Docker only uses and exposes a subset of what is possible
lxc-create -n test -t busybox
lxc-start -d -n test
lxc-info -n test
lscgroup | grep lxc
/var/lib/lxc/test/config
ls /var/lib/lxc/test/ # tree

# lxc-attach -n test

PID=$(lxc-info -p -n test | awk '{print $2}')
CGROUPS=$(lscgroup | awk -F: '/test/ {print $1}' | paste -sd,)
inside() {
  cgexec -g "$CGROUPS:/lxc/test" -- \
    nsenter --target $PID --mount --uts --ipc --net --pid -- "$@"
  # hasn't dropped capabilities
  # can be used to do things inside that are otherwise not allowed by lxc or docker
  # such as additional mount points, routing changes etc.
}

inside cat /proc/self/cgroup
inside ls -al /proc/$PID/ns/

# other uses http://uwsgi-docs.readthedocs.org/en/latest/Namespaces.html
# exploring cgroups
tree -fd /sys/fs/cgroup/
tree -fd /sys/fs/cgroup/ | grep docker
tree -fd /sys/fs/cgroup/ | grep lxc

libcgroup / libcgroup-tools (ubuntu: cgroup-bin)
lssubsys
lscgroup
cgget

# to get list of cgroups docker is using
CGROUPS=$(lscgroup | awk -F: '/docker/ {print $1}' | uniq | paste -sd,)
cgexec -g "$CGROUPS:/docker/$CID"

# other tooling for working with cgroups:  
#apt-get install python-dev
#pip install cgroup-utils
#https://pypi.python.org/pypi/cgroup-utils/0.5

# working with procs / cgroups 
ps -O cgroup
ps -e -O cgroup
cat /proc/$PID/cgroup
alias psc='ps xawf -eo pid,user,cgroup,args'

apt-get install ruby ruby-dev libcap-dev
gem install cap2
ruby -e "require 'pp'; require 'cap2'; pp Cap2.process($PID).getcaps[:effective]"

… examine /usr/local/bin/dockhack and continue exploring with it

Interlude: Security

Security & multi-tenant: caveat emptor

point to selinux / apparmour, but not covered

Core Docker Concepts & Commands & API (9:30 - 10:15)

the daemon process and its options

  • docker -h
  • exposing its API via -H
  • running various storage backends on the same system
  • explore -s drivers and fs layout

using command outputs and exit codes for scripting in bash

containers

  • run, stop/kill, start, restart, wait
  • ps, inspect, top, logs, port
  • attach
  • diff, cp, commit
  • rm

images

  • images
  • import
  • tag
  • inspect
  • history
  • save/load
  • rmi
  • build … covered later

registries

  • push
  • pull
  • search

use the power of unix shell scripting

http://stedolan.github.io/jq/manual/ docker ps -a -q | xargs docker inspect | jq -c ‘.[] | {Name, exit: .State.ExitCode}

some examples http://www.wouterdanes.net/2014/04/16/some-docker-tips-and-tricks.html

API via Python

mention REST api but use Python wrapper

local via unix domain socket

  • shareable via mount binds

remote http auth

differences between equivalent cli commands

  • some commands & arguments are subtly different

using the api integrated into ansible & salt:

cleaning up old unused containers & images

Build files (10:15 - 10:45)

Build files basics

syntax & semantics

docker build (and options) vs other approaches for creating images (tarball imports, etc.)

choosing a base image

http://phusion.github.io/baseimage-docker/
  • for your own internal use VS sharing with the world
    • for your own use, bake all your common utils and config into the base
      • minimize size & layering
    • for external use, keep the base light or even better use a common 3rd party base image

integration with config management tools

application packaging and configuration

best practices

Image Management & Volumes (10:45 - 11:20)

public index

trusted builds

using a private registry

host bind mounts of volumes

avoid vfs volumes if you can

-volumes-from for data volume sharing

http://docs.docker.io/use/working_with_volumes/

management of application data (e.g. postgresql data/) in volumes

https://github.com/discordianfish/docker-exporter/ https://github.com/discordianfish/docker-backup/ https://github.com/discordianfish/docker-lloyd/ backs up to s3 or use btrfs snapshots + send/receive

TLC, Garbage Collection and Handling Docker Upgrades

Running Postgresql and Other DBs

Networking (11:20 - 12)

quick demonstration of manually created network namespace

CID=short sha
TASKS=/sys/fs/cgroup/devices/docker/$CID*/tasks
PID=$(head -n 1 $TASKS) # use --format instead

mkdir -p /var/run/netns
ln -sf /proc/$PID/ns/net /var/run/netns/$CID
ip netns exec $CID ifconfig
ip netns exec $CID ip {link,addr,route} ...
ip netns exec $CID netstat -i
ip netns exec $CID tcpdump ...
ip netns exec $CID ss 

exposing ports and binding to host interfaces

dns options

intercontainer networking

via -icc or custom bridges and lxc network options

-icc=false vs true with iptables -Ln

same with links see diagrams in http://www.slideshare.net/hansode/hack-for-dockers-network

network bridging

sharing unix domain sockets & fifos between containers

host networking in docker 0.11

trouble-shooting

tcpdump -i docker0

-mtu option to docker daemon for when default is too large

configuring alternate local network topologies via pipework

software defined networking via Open vSwitch

http://goldmann.pl/blog/2014/01/21/connecting-docker-containers-on-multiple-hosts/ https://gist.github.com/noteed/8656989 https://communities.vmware.com/blogs/kevinbarrass for vmware examples that are also relevant http://networkstatic.net/open-vswitch-gre-tunnel-configuration/

simpler gre tunnels

http://tier.cs.berkeley.edu/drupal/howto/ip-tunnel-using-gre-on-linux http://tldp.org/HOWTO/Adv-Routing-HOWTO/lartc.tunnel.gre.html be aware of mtu size issue http://www.cisco.com/c/en/us/support/docs/ip/generic-routing-encapsulation-gre/13725-56.html

overhead of various approaches

resources

docker inside of ec2 VPC

http://serverfault.com/questions/568736/expose-docker-containers-to-vpc-network

docker openvpn

http://blog.docker.io/2013/09/docker-joyent-openvpn-bliss/

advanced linux networking

http://www.lartc.org/ https://wiki.archlinux.org/index.php/Advanced_Traffic_Control https://www.digitalocean.com/community/articles/how-to-use-iproute2-tools-to-manage-network-configuration-on-a-linux-vps

Afternoon 1-5

Monitoring, Logging and Error Detection (1 - 1:20)

logging currently sucks & is being worked on

https://groups.google.com/forum/m/#!topic/docker-dev/3paGTWD6xyw

container logging options

using logentries service for demo

wget https://raw.github.com/logentries/le/master/install/linux/logentries_install.sh && sudo bash logentries_install.sh https://logentries.com https://blog.logentries.com/2014/03/how-to-run-rsyslog-in-a-docker-container-for-logging/

logging via stdout of container

docker run –name logtest -d busybox sh -c “while true; do uptime; sleep 5; done” docker logs -f -t logtest | logger -t ‘docker:logtest’ docker run –name logtest2 busybox sh -c “while true; do uptime; sleep 5; done” | logger -t ‘docker:direct’

logging via syslog or logstash to a log service container

logging via bind mount of /dev/log /dev/kmsg

similar to lxc.kmsg

ugly hacks watching docker’s file system

http://jasonwilder.com/blog/2014/03/17/docker-log-management-using-fluentd/

docker events api

  • severely limited at the moment
  • only container events are shown
  • will not survive daemon restart

https://github.com/discordianfish/docker-spotter

agent on host that uses docker inspect to get details of each create event

graph_root=/lxc/docker
container_creations() {
  docker events --since "1" | awk '/create/ {gsub(":",""); print $5; fflush()}'
}

log_creations() {
  local config_file
  while IFS= read -r cid; do 
     docker inspect "$cid" | jq -M -c '.[]'
  done
}

watch_containers() {
 container_creations | log_creations
}

linux cgroup stats via /proc

http://blog.docker.io/2013/10/gathering-lxc-docker-containers-metrics/

monitoring container disk space usage

host / container / app monitoring with sensu

Processes & Supervision (1:20 - 2)

Docker’s single process philosophy

counter args: http://phusion.github.io/baseimage-docker/

versus more traditional vm-like init + procs

tradeoffs and use cases for each

using init

using runit http://tech.paulcz.net/2013/10/managing-docker-services-with-this-one-easy-trick.html

using supervisord

http://docs.docker.io/examples/using_supervisord/

process supervision within and between containers

my hack for attaching privileged processes

integration with host system init

http://docs.docker.io/use/host_integration/

supervising other containers from a supervisor container

Docker for Dev / Simulations / Testing / CI (2 - 3)

Jenkins integration

https://wiki.jenkins-ci.org/display/JENKINS/Docker+Plugin

From the authors of Fig https://github.com/orchardup/docker-jenkins/blob/master/Dockerfile

http://www.ebaytechblog.com/2014/04/04/delivering-ebays-ci-solution-with-apache-mesos-part-i/#.U3yrPIm9LCS

Blockade http://blockade.readthedocs.org for Testing Network Failures

resources

Docker for Image / Artifact Packing (3 - 3:10)

If output is a single flat image:

  • vs chroot
  • vs lxc
  • vs packer

If output is a diff or layered set of diffs against a base image:

Docker for Production (3:10 - 4:30)

Docker buildfiles / containers as the unit of composition vs other units of composition

  • mutable long-lived physical boxes or vms
    • snow-flakes
    • config managed
  • mutable but short-lived vms
  • immutable vms

Public Cloud economics & performance

  • better packing and utilization
  • remember it’s still not native performance.
  • good usage of docker won’t add much extra overhead but you’re already virtualized

Key components and concerns

Service Discovery & Inter-Container Relationships

simple inter-container links and problems with this approach
more sophisticated and reliable approaches
haproxy combined with other options
  • a la Airbnb’s SmartStack
Ambassador pattern

monitoring, logging and metrics (see earlier in the day)

backup and data management

  • use host mount-bind volumes (see earlier in day)

high-availability & load balancing

https://github.com/discordianfish/haproxy-docker/blob/master/README.md http://brianketelsen.com/2014/02/25/using-nginx-confd-and-docker-for-zero-downtime-web-updates/ http://www.centurylinklabs.com/auto-loadbalancing-with-fig-haproxy-and-serf/

saltstack in ha: same principles apply to docker+salt https://www.youtube.com/watch?v=R1bEEzwYeqk&app=desktop

orchestration & config management

  • use what you know best
    • salt
    • ansible
    • puppet
    • chef
    • etc.

Application Lifecycle

options for handling of releases and configuration changes

atomic changes

rollback option via layers/tags

Resource limits

via docker run options

  • cpu -c –cpu-shares
  • memory -m –memory

using cgroups

external enforced limits

  • disk space quotas
  • public cloud provider tools

PaaS like tools for Docker

Host OS Integration / Orchestration, etc.

CoreOS and Cluster Deployment with Fleet

Conclusion (4:30)

Review

Key Takeaway Points

  • too early to really know about ‘best practices’:
    • think critically, measure, test, and monitor
    • what is your unit of deployment
  • be wary of the less used backend drivers which haven’t had much battle testing yet
    • e.g. lvm
    • use device-mapper, btrfs or aufs
    • use libcontainer instead of lxc execution engine
  • pay attention to error reporting and handling. How does your infrastructure handle the unhappy path.
  • keep an eye on the issues on github for bugs that may affect you
  • try to develop your apps & systems so you can deploy to docker OR elsewhere. There is no need to lock yourself into docker-only approaches.

Immutable Infrastructure and ‘Phoenix’ Servers

Final Questions

Is it ready for production use?

Reminder re Security

Resources

Interesting Docker Related Tools and Projects

Interesting pull requests / issues to watch

‘docker driver …’ command for driver backend commands such as resize-pool / resize

moby/moby#4572 support for user namespaces

Articles about Docker in Use

Optional Discussions

Food & Drinks Afterwards