Deploying

with Docker
DevOps Days PGH
2014.05.30
a.k.a. provisioning docker containers and images with Chef
Deploying

wi...
Why do we still need

<insert tool here>?
But… we have
Dockerfiles!
It’s a shell-script?
$ cat SomeApp/Dockerfile



FROM ubuntu:13.10



RUN apt-get update; apt-get install apache

RUN sed ’...
I ♥ #!/bin/bash
. oo # https://raw.githubusercontent.com/

# ewindisch/bashoo/master/lib/oo



# Classes are created impli...
stack:~/devstack$ wc -l stack.sh functions 

functions-common 

lib/* lib/*/* | tail -n1
15490 total
DevOps

or
crazy-sauce
?
$ cd ~/rpm-chef

$ cat Dockerfile

FROM fedora

RUN yum update 

yum -y install chef
DockerChef
$ cd ~/omnibus-chef

$ cat Dockerfile

FROM fedora"
RUN curl -L 

https://www.opscode.com/chef/install.sh |

/bin/bash
Doc...
Traditional Chef
Hardware
OS
Linux
Chef
Installs Chef
Runs
Configures
Images on HW

is usually mutable
Hardware
Image
Linux
Chef
Installs Chef
Image'
Linux
Chef
Creates
Replaces
Runs
Ephemeral environments

are (somewhat) immutable.
Hypervisor
Image
Linux
Chef
Runs
Image'
Linux
Chef
Chef
Runs
Configures
V...
Chef-for-runtime
$ cat Dockerfile

FROM fedora

RUN yum update; 

yum -y install chef

ADD http://x/receipes.tar.gz /opt/c...
Containers

are

THINGS
X
X
Servers vs Things


Pets vs Cattle
LET US 

BAKE

IMAGES!
Let us
BAKE
images!
Containers are like
ephemeral VMs*
* Docker containers don’t HAVE to be ephemeral,
but it’s TheRightThing
Docker
Image
Lin...
Bakery Chef
$ cat Dockerfile

FROM fedora

RUN yum update; 

yum -y install chef"


ADD http://x/receipes.tar.gz /opt/chef...
Burning configuration

into images.
Docker ContainerInitiates Creates
Image
Linux
Chef
Chef
Runs
Configures
Build Creates
Expanded view:

Burning configuration into
images.
Docker Image tagInitiates
Image'
Linux
Chef
Chef
Build
Image
Linux
Chef...
Anatomy of a Docker
+Chef build & run
Docker ContainerInitiates Creates
Image
Linux
Chef
Chef
Runs
Configures
Chef
Runs
Con...
For All The Things!
$ cat Dockerfile

FROM fedora

RUN yum update; 

yum -y install chef



ADD http://x/receipes.tar.gz /...
Does it converge?
$ docker build —rm .

$ echo $? # pass or fail
(This is great use of Docker as an
alternative to VMs for...
Deploying Docker
(for real this time)
#!/bin/bash -x
aws ec2 run-instances 
--image-id ami-e55a648c 
--key-name my-key 
--user-data "#include https://get.docker...
# using https://github.com/bflad/chef-docker


$ cat cookbooks/docker-registry/default.rb

# Pull latest image
docker_imag...
docker::run { 'helloworld':

image => 'base',

command => '/bin/sh -c "while true; do echo
hello world; sleep 1; done"',

...
Orchestration for Docker

with OpenStack Heat
DockerInc::Docker:
:Container
VMs
Baremetal
Heat Workflow
Heat API
VM
Docker
NovaNova resource
Docker resource
Container1
Container2
Container3
HOT
heat_template_version: 2013-05-23
description: shared volumes example
resources:
my_instance:
type: OS::Nova::Server
prope...
Ansible
- hosts: web

sudo: yes

tasks:

- name: ensure redis container is running

docker: image=crosbymichael/redis name...
Mesos Flynn.io
Creating Containers
is Easy
Managing them
SUCKS
needs improvement
This is probably
material for another
talk…
Container Inventory
• discoverd / sdutil
• serf
• skydock
• others?
X
X
Q & A
@ewindisch
Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH
Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH
Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH
Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH
Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH
Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH
Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH
Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH
Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH
Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH
Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH
Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH
Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH
Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH
Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH
Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH
Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH
Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH
Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH
Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH
Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH
Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH
Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH
Upcoming SlideShare
Loading in...5
×

Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH

22,420

Published on

Using Docker to bake configuration.

Published in: Technology

Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH

  1. 1. Deploying
 with Docker DevOps Days PGH 2014.05.30 a.k.a. provisioning docker containers and images with Chef Deploying
 with Docker (or not)
  2. 2. Why do we still need
 <insert tool here>?
  3. 3. But… we have Dockerfiles!
  4. 4. It’s a shell-script? $ cat SomeApp/Dockerfile
 
 FROM ubuntu:13.10
 
 RUN apt-get update; apt-get install apache
 RUN sed ’s/something/else/‘ /etc/apache/httpd.conf
 
 ADD shell-script.sh
 RUN shell-script.sh
 
 RUN [‘/usr/bin/apachectl’, ‘start’]
  5. 5. I ♥ #!/bin/bash . oo # https://raw.githubusercontent.com/
 # ewindisch/bashoo/master/lib/oo
 
 # Classes are created implicitly through functions
 function MsgWriter::new {
 self=$1; shift
 msg=$1; shift
 instance_var $self msg $msg 
 }
 function MsgWriter::write {
 self=$1; shift
 echo $($self.msg)
 }
 
 new terminal is MsgWriter “Hello World”
 terminal.write
  6. 6. stack:~/devstack$ wc -l stack.sh functions 
 functions-common 
 lib/* lib/*/* | tail -n1 15490 total
  7. 7. DevOps
 or crazy-sauce ?
  8. 8. $ cd ~/rpm-chef
 $ cat Dockerfile
 FROM fedora
 RUN yum update 
 yum -y install chef DockerChef
  9. 9. $ cd ~/omnibus-chef
 $ cat Dockerfile
 FROM fedora" RUN curl -L 
 https://www.opscode.com/chef/install.sh |
 /bin/bash DockerChef
  10. 10. Traditional Chef Hardware OS Linux Chef Installs Chef Runs Configures
  11. 11. Images on HW
 is usually mutable Hardware Image Linux Chef Installs Chef Image' Linux Chef Creates Replaces Runs
  12. 12. Ephemeral environments
 are (somewhat) immutable. Hypervisor Image Linux Chef Runs Image' Linux Chef Chef Runs Configures VM Accesses COW
  13. 13. Chef-for-runtime $ cat Dockerfile
 FROM fedora
 RUN yum update; 
 yum -y install chef
 ADD http://x/receipes.tar.gz /opt/chef" ADD solo.rb /etc/chef/solo.rb" CMD chef-solo -c /etc/chef/solo.rb ; ! apachectl start
  14. 14. Containers
 are
 THINGS
  15. 15. X
  16. 16. X
  17. 17. Servers vs Things 
 Pets vs Cattle
  18. 18. LET US 
 BAKE
 IMAGES! Let us BAKE images!
  19. 19. Containers are like ephemeral VMs* * Docker containers don’t HAVE to be ephemeral, but it’s TheRightThing Docker Image Linux Chef Runs Image' Linux Chef Chef Runs Configures Container Accesses COW TM
  20. 20. Bakery Chef $ cat Dockerfile
 FROM fedora
 RUN yum update; 
 yum -y install chef" 
 ADD http://x/receipes.tar.gz /opt/chef" ADD solo.rb /etc/chef/solo.rb" RUN chef-solo -c /etc/chef/solo.rb

  21. 21. Burning configuration
 into images. Docker ContainerInitiates Creates Image Linux Chef Chef Runs Configures Build Creates
  22. 22. Expanded view:
 Burning configuration into images. Docker Image tagInitiates Image' Linux Chef Chef Build Image Linux Chef Creates Creates Runs Creates References 1 2
  23. 23. Anatomy of a Docker +Chef build & run Docker ContainerInitiates Creates Image Linux Chef Chef Runs Configures Chef Runs Configures Build Creates Stage 1 Stage 2
  24. 24. For All The Things! $ cat Dockerfile
 FROM fedora
 RUN yum update; 
 yum -y install chef
 
 ADD http://x/receipes.tar.gz /opt/chef" ADD solo-stage1.rb /etc/chef/solo-stage1.rb" ADD solo-stage2.rb /etc/chef/solo-stage2.rb" RUN chef-solo -c /etc/chef/solo-stage1.rb" CMD chef-solo -c /etc/chef/solo-stage2.rb; " apachectl start
  25. 25. Does it converge? $ docker build —rm .
 $ echo $? # pass or fail (This is great use of Docker as an alternative to VMs for testing Chef recipes targeting non-Docker production systems)
  26. 26. Deploying Docker (for real this time)
  27. 27. #!/bin/bash -x aws ec2 run-instances --image-id ami-e55a648c --key-name my-key --user-data "#include https://get.docker.io” 
 ip=$(aws ec2 describe-instances --output json --filter Name=instance-state-name,Values=running | python -c 'import json; import sys; print json.load(sys.stdin) [“Reservations”][0]["Instances"][0]["PublicIpAddress"]') 
 ssh ubuntu@$ip sudo docker run cirros
  28. 28. # using https://github.com/bflad/chef-docker 
 $ cat cookbooks/docker-registry/default.rb
 # Pull latest image docker_image 'samalba/docker-registry' ! # Run container exposing ports docker_container 'samalba/docker-registry' do detach true port '5000:5000' env 'SETTINGS_FLAVOR=local' volume '/mnt/docker:/docker-storage' end
 
 $ knife ec2 server create # yada yada yada
  29. 29. docker::run { 'helloworld':
 image => 'base',
 command => '/bin/sh -c "while true; do echo hello world; sleep 1; done"',
 ports => ['4444', '4555'],
 links => ['mysql:db'],
 use_name => true,
 volumes => ['/var/lib/couchdb', '/var/log'],
 volumes_from => '6446ea52fbc9',
 memory_limit => 10485760, # bytes 
 username => 'example',
 hostname => 'example.com',
 env => ['FOO=BAR', 'FOO2=BAR2'],
 dns => ['8.8.8.8', '8.8.4.4'],
 restart_service => true,
 }
  30. 30. Orchestration for Docker
 with OpenStack Heat DockerInc::Docker: :Container VMs Baremetal
  31. 31. Heat Workflow Heat API VM Docker NovaNova resource Docker resource Container1 Container2 Container3 HOT
  32. 32. heat_template_version: 2013-05-23 description: shared volumes example resources: my_instance: type: OS::Nova::Server properties: key_name: ewindisch_key image: ubuntu-precise flavor: m1.large user_data: #include https://get.docker.io ftp_container: type: DockerInc::Docker::Container properties: docker_endpoint: { get_attr: 
 [my_instance, first_address] } image: mikz/vsftpd
 ports: [ “21:21” ]
 volumes: [ “/ftp” ] name: “FTP”
 
 
 apache_container: type: DockerInc::Docker::Container properties: docker_endpoint: { get_attr: 
 [my_instance, first_address] } image: fedora/apache ports: [ “80:80” ] volumes-from: “FTP” cmd: “rm -rf /var/www; 
 ln -s /ftp /var/www;
 /run-apache.sh”
  33. 33. Ansible - hosts: web
 sudo: yes
 tasks:
 - name: ensure redis container is running
 docker: image=crosbymichael/redis name=redis
 
 - name: ensure redis_ambassador container is running
 docker: image=svendowideit/ambassador 
 ports=6379:6379 links=redis:redis 
 name=redis_ambassador_ansible
  34. 34. Mesos Flynn.io
  35. 35. Creating Containers is Easy
  36. 36. Managing them SUCKS needs improvement
  37. 37. This is probably material for another talk…
  38. 38. Container Inventory • discoverd / sdutil • serf • skydock • others?
  39. 39. X
  40. 40. X
  41. 41. Q & A @ewindisch
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×