Docker

@marekgoldmann

PoznaƄ JUG, 3rd June 2014

Docker

Applications are complex

Mess

http://www.reddit.com/r/pics/comments/nf8la/im_always_tempted_to_switch_two_random_cables_to/

Different deployment environments

Mess

http://www.shedworking.co.uk/2012/03/nuts-and-bolts-cable-ties.html

But how?

Unified deployment format

Docker

A project to manage containers.

Containers?

Yes, a lightweight operating system virtualization.

How this compares to a virtual machine?

It's completely different.

Comparison

Virtual Machine (KVM, VMware)Container (LXC, OpenVZ)
HardwareSimulatedUses it (almost) directly
Supported OS'esAlmost anyOnly Linux
SpaceUser spaceKernel space
SeparationFullControl Groups (cgroups)
Startup timeSeconds to minutesMiliseconds
ScalabilityA fewSky is the limit (thousands)
Custom kernelYesNo
Enterprise features (live migration, etc)YesNo
Ease of creationModerateEasy
Time consumption of creationHighLow
SizeHUGESmall

Who's behind Docker?

Docker, Inc. and a powerful community.

Speaking of community...

  • GitHub
    • >800 watchers
    • >11000 stars
    • >1800 forks
    • >500 open issues
    • >80 pull requests
  • Over 400 contributors
    • avg 17 commits / day
    • 90% are external
  • Many meetups all over the world

Achieved after 15 months since first commit to GitHub

Glossary

  • Image: a (read-only) template with filesystem and data
  • Container: a running image
  • Registry: place where images are hosted/shared

Main concepts

  • An image can be linked to a parent image
  • Image not having a parent is called base image
  • Container has a state, whereas image doesn't
  • You can launch multiple containers from an image

How does it work?

  • cgroups
    • groups processes in trees, single entity
  • namespaces
    • process isolation; network, pid, filesystem, etc
  • filesystem
    • aufs, btrfs, devicemapper

Show it!

Creating Docker images

It's simple! Use Dockerfiles.

Dockerfile

A plain text file with instructions that automates building the image.

Dockerfile example


# Base on the Fedora 20 image
FROM fedora

# Upgrade the image
RUN yum -y update

# Install WildFly application server
RUN yum -y install wildfly

# Run WildFly after container boot
ENTRYPOINT /usr/share/wildfly/bin/standalone.sh -c standalone-ha.xml -b 0.0.0.0
					

This should be saved as Dockerfile

Building the image

docker build .

Building the image


$ docker build .
Uploading context  2.56 kB
Uploading context 
Step 0 : FROM fedora
 ---> 58394af37342

[SNIP]

Step 3 : ENTRYPOINT /usr/share/wildfly/bin/standalone.sh -c standalone-ha.xml -b 0.0.0.0
 ---> Running in 72f63daffbd1
 ---> e91c26099a67
Removing intermediate container 72f63daffbd1
Successfully built e91c26099a67
          

We've built image e91c26099a67

Modifyng the image

  1. Change the Dockerfile
  2. Execute the build command once again

Image repositories

  1. Private: for example hosted inside a company
  2. Public: index.docker.io

OK, great, but...

Use-cases?

  • Want your own PaaS?
  • Automated testing and CI
  • Deploying scalable apps

PaaS

It's (fairly) easy to create a PaaS with Docker

There is even a tutorial to create one in 5 minutes...

Continuous Integration

  1. You commit
  2. CI builds the app
  3. CI creates an image with the new app
  4. CI starts a container from new image
  5. Integration tests are executed on a real application
  6. Profit!

Scalable apps

  • Requirement: prepare your app to be easily scalable
  • Starting a container is fast and cheap
  • Extending a (for example WildFly) cluster is easy
  • Profit!
Much JBoss
http://projectatomic.io

100 httpd servers in one minute, go!

Thanks!

(and remember to Docker all the things!)

Slides

Attributions:

  • https://www.docker.io/