Dockerizing your applications - Docker workshop @Twitter

12
Twitter San Francisco, CA 2013-11-05 Dockerizing your applications Daniel Mizyrycki [email protected] docker

description

Docker is an open-source project to easily create lightweight, portable, self-sufficient containers from any application. The same container that a developer builds and tests on a laptop can run at scale, in production, on VMs, bare metal, OpenStack clusters, public clouds and more.

Transcript of Dockerizing your applications - Docker workshop @Twitter

Page 1: Dockerizing your applications - Docker workshop @Twitter

Twitter San Francisco, CA 2013-11-05

Dockerizing your applications

Daniel [email protected]

docker

Page 2: Dockerizing your applications - Docker workshop @Twitter

Introduction

Dockerizing a typical desktop application

Page 3: Dockerizing your applications - Docker workshop @Twitter

Downloads

* Download Dockerwget -O docker http://get.docker.io/builds/Linux/x86_64/docker-latest

* Download data and firefox Dockerfiles from contrib/desktop-integration

wget http://raw.github.com/dotcloud/docker/master/ contrib/desktop-integration/data/Dockerfile

wget http://raw.github.com/dotcloud/docker/master/ contrib/desktop-integration/firefox/Dockerfile

Page 4: Dockerizing your applications - Docker workshop @Twitter

Building images with a Dockerfile

* base image

* load new packages

* optional customization

* optional addition of host files

* optional run command

Page 5: Dockerizing your applications - Docker workshop @Twitter

Data Dockerfile (Example of customization)

# Smallest base image, just to launch a containerfrom busyboxmaintainer Daniel Mizyrycki <[email protected]>

# Create a regular userrun echo 'sysadmin:x:1000:1000::/data:/bin/sh' >> /etc/passwdrun echo 'sysadmin:x:1000:' >> /etc/group

# Create directory for that userrun mkdir /datarun chown sysadmin.sysadmin /data

# Add content to /data. This will keep sysadmin ownershiprun touch /data/init_volume

# Create /data volumeVOLUME /data

Page 6: Dockerizing your applications - Docker workshop @Twitter

Docker and the desktop:

How to communicate with the desktop?

Video: X11 unix socket. /tmp/.X11-unix/X0

Audio: Alsa. /dev/snd plus access to the physical devices

Page 7: Dockerizing your applications - Docker workshop @Twitter

Launch Docker

docker -d &

Building containers

cd data; docker build -t data -rm .cd firefox; docker build -t firefox -rm .

Page 8: Dockerizing your applications - Docker workshop @Twitter

Running ephemeral Firefox container

docker run -e DISPLAY=unix$DISPLAY \ -v /tmp/.X11-unix:/tmp/.X11-unix \ -v /dev/snd:/dev/snd \ -lxc-conf='lxc.cgroup.devices.allow = c 116:* rwm' \ firefox

Page 9: Dockerizing your applications - Docker workshop @Twitter

Running stateful data-on-host Firefox container

docker run -e DISPLAY=unix$DISPLAY \ -v /data/firefox:/data \ -v /tmp/.X11-unix:/tmp/.X11-unix \ -v /dev/snd:/dev/snd \ -lxc-conf='lxc.cgroup.devices.allow = c 116:* rwm' \ firefox

Page 10: Dockerizing your applications - Docker workshop @Twitter

Create dockerized data container

docker run -name firefox-data data true

Monitor status in the data container

while true; do docker run -volumes-from firefox-data busybox ls -al /data sleep 3; clear; done

Page 11: Dockerizing your applications - Docker workshop @Twitter

Running stateful firefox with dockerized data container

docker run -e DISPLAY=unix$DISPLAY \ -volumes-from firefox-data \ -v /tmp/.X11-unix:/tmp/.X11-unix \ -v /dev/snd:/dev/snd \ -lxc-conf='lxc.cgroup.devices.allow = c 116:* rwm' \ firefox

Page 12: Dockerizing your applications - Docker workshop @Twitter