Ladislav	
  Prskavec	
  @abtris	
  -­‐	
  	
  DEVEL	
  9.11.2013

1
Docker	
  is	
  an	
  open-­‐source	
  project	
  	
  
to	
  easily	
  create	
  lightweight,	
  portable,	
  self-­‐sufficient	
  containers	
  
from	
  any	
  applicaHon.	
  

2
The	
  same	
  container	
  that	
  a	
  developer	
  builds	
  and	
  tests	
  on	
  a	
  
laptop	
  can	
  run	
  at	
  scale,	
  in	
  producHon,	
  on	
  VMs,	
  bare	
  metal,	
  
OpenStack	
  clusters,	
  public	
  clouds	
  and	
  more.
3
4
BeNer	
  than	
  VMs
★ Size

5
BeNer	
  than	
  VMs
★ Size	
  
★ Performance

6
BeNer	
  than	
  VMs
★ Size	
  
★ Performance	
  
★ Portability

7
BeNer	
  than	
  VMs
★ Size	
  
★ Performance	
  
★ Portability	
  
★ Hardware-­‐centric

8
Escape	
  dependency	
  hell
★ Cross-­‐plaRorm	
  dependencies

9
Escape	
  dependency	
  hell
★ Cross-­‐plaRorm	
  dependencies	
  
★ ConflicHng	
  dependencies

10
Escape	
  dependency	
  hell
★ Cross-­‐plaRorm	
  dependencies	
  
★ ConflicHng	
  dependencies	
  
★ Custom	
  dependencies

11
Here's	
  a	
  typical	
  Docker	
  build	
  process	
  (Dockerfile)
from	
  ubuntu:12.10	
  
run	
  apt-­‐get	
  update	
  
run	
  DEBIAN_FRONTEND=noninteractive	
  apt-­‐get	
  install	
  -­‐q	
  -­‐y	
  python	
  
run	
  DEBIAN_FRONTEND=noninteractive	
  apt-­‐get	
  install	
  -­‐q	
  -­‐y	
  python-­‐pip	
  
run	
  pip	
  install	
  django	
  
run	
  DEBIAN_FRONTEND=noninteractive	
  apt-­‐get	
  install	
  -­‐q	
  -­‐y	
  curl	
  
run	
  curl	
  -­‐L	
  https://github.com/shykes/helloflask/master.tar.gz	
  |	
  tar	
  -­‐xzv	
  
run	
  cd	
  helloflask-­‐master	
  &&	
  pip	
  install	
  -­‐r	
  requirements.txt

12
Under	
  the	
  hood
★ GO	
  
★ The	
  cgroup	
  and	
  namespacing	
  capabiliHes	
  of	
  the	
  Linux	
  kernel

13
Under	
  the	
  hood
★ GO	
  
★ The	
  cgroup	
  and	
  namespacing	
  capabiliHes	
  of	
  the	
  Linux	
  kernel	
  
★ AUFS,	
  a	
  powerful	
  union	
  filesystem	
  with	
  copy-­‐on-­‐write	
  
capabiliHes

14
Under	
  the	
  hood
★ GO	
  
★ The	
  cgroup	
  and	
  namespacing	
  capabiliHes	
  of	
  the	
  Linux	
  kernel	
  
★ AUFS,	
  a	
  powerful	
  union	
  filesystem	
  with	
  copy-­‐on-­‐write	
  
capabiliHes	
  
★ lxc,	
  a	
  set	
  of	
  convenience	
  scripts	
  to	
  simplify	
  the	
  creaHon	
  of	
  
Linux	
  containers

15
Zero	
  downHme	
  deployment

using	
  private	
  registry
16
App	
  running	
  in	
  prod	
  hNp://praguejs.cz	
  
!
vagrant@precise64:~$	
  docker	
  ps	
  
!
CONTAINER	
  ID	
  	
  	
  	
  	
  	
  	
  	
  IMAGE	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  
!
b2332dffe	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  registry.abtris.cz:5000/praguejs:latest	
  
-­‐	
  Build	
  local	
  
>	
  docker	
  build	
  -­‐t=praguejs	
  .	
  
-­‐	
  Test	
  local	
  
>	
  docker	
  run	
  -­‐p	
  49200:3333	
  praguejs	
  
hNp://localhost:49200	
  
-­‐	
  Change	
  some	
  files	
  
-­‐	
  Rebuild	
  &	
  test	
  
>	
  docker	
  build	
  -­‐t	
  praguejs	
  
>	
  docker	
  run	
  -­‐p	
  49200:3333	
  praguejs
17
Push	
  to	
  producHon	
  
•

Tag	
  image	
  in	
  order	
  to	
  push	
  it

>	
  docker	
  tag	
  praguejs	
  registry.abtris.cz:5000/praguejs	
  

•

Push	
  image	
  to	
  local	
  registry

>	
  docker	
  push	
  registry.abtris.cz:5000/praguejs	
  

•

On	
  producHon	
  server,	
  pull	
  image

>	
  docker	
  pull	
  registry.abtris.cz:5000/praguejs	
  

•

Start	
  new	
  container	
  

>	
  docker	
  run	
  -­‐d	
  -­‐p	
  127.0.0.1::3333	
  <image>	
  

vagrant@precise64:~$	
  docker	
  ps	
  
• Change	
  configuraHon	
  at	
  nginx/haproxy	
  and	
  restart	
  
CONTAINER	
  ID	
  	
  	
  	
  	
  	
  	
  	
  IMAGE	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  
b2332dffe	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  registry.abtris.cz:5000/praguejs:latest	
  	
  
• See	
  changes	
  live
d45222331	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  1b4f43asds	
  
18
19
hNp://m.doporucim.cz/Docker
20

Docker.io

  • 1.
    Ladislav  Prskavec  @abtris  -­‐    DEVEL  9.11.2013 1
  • 2.
    Docker  is  an  open-­‐source  project     to  easily  create  lightweight,  portable,  self-­‐sufficient  containers   from  any  applicaHon.   2
  • 3.
    The  same  container  that  a  developer  builds  and  tests  on  a   laptop  can  run  at  scale,  in  producHon,  on  VMs,  bare  metal,   OpenStack  clusters,  public  clouds  and  more. 3
  • 4.
  • 5.
  • 6.
    BeNer  than  VMs ★Size   ★ Performance 6
  • 7.
    BeNer  than  VMs ★Size   ★ Performance   ★ Portability 7
  • 8.
    BeNer  than  VMs ★Size   ★ Performance   ★ Portability   ★ Hardware-­‐centric 8
  • 9.
    Escape  dependency  hell ★Cross-­‐plaRorm  dependencies 9
  • 10.
    Escape  dependency  hell ★Cross-­‐plaRorm  dependencies   ★ ConflicHng  dependencies 10
  • 11.
    Escape  dependency  hell ★Cross-­‐plaRorm  dependencies   ★ ConflicHng  dependencies   ★ Custom  dependencies 11
  • 12.
    Here's  a  typical  Docker  build  process  (Dockerfile) from  ubuntu:12.10   run  apt-­‐get  update   run  DEBIAN_FRONTEND=noninteractive  apt-­‐get  install  -­‐q  -­‐y  python   run  DEBIAN_FRONTEND=noninteractive  apt-­‐get  install  -­‐q  -­‐y  python-­‐pip   run  pip  install  django   run  DEBIAN_FRONTEND=noninteractive  apt-­‐get  install  -­‐q  -­‐y  curl   run  curl  -­‐L  https://github.com/shykes/helloflask/master.tar.gz  |  tar  -­‐xzv   run  cd  helloflask-­‐master  &&  pip  install  -­‐r  requirements.txt 12
  • 13.
    Under  the  hood ★GO   ★ The  cgroup  and  namespacing  capabiliHes  of  the  Linux  kernel 13
  • 14.
    Under  the  hood ★GO   ★ The  cgroup  and  namespacing  capabiliHes  of  the  Linux  kernel   ★ AUFS,  a  powerful  union  filesystem  with  copy-­‐on-­‐write   capabiliHes 14
  • 15.
    Under  the  hood ★GO   ★ The  cgroup  and  namespacing  capabiliHes  of  the  Linux  kernel   ★ AUFS,  a  powerful  union  filesystem  with  copy-­‐on-­‐write   capabiliHes   ★ lxc,  a  set  of  convenience  scripts  to  simplify  the  creaHon  of   Linux  containers 15
  • 16.
    Zero  downHme  deployment using  private  registry 16
  • 17.
    App  running  in  prod  hNp://praguejs.cz   ! vagrant@precise64:~$  docker  ps   ! CONTAINER  ID                IMAGE                                                                         ! b2332dffe                      registry.abtris.cz:5000/praguejs:latest   -­‐  Build  local   >  docker  build  -­‐t=praguejs  .   -­‐  Test  local   >  docker  run  -­‐p  49200:3333  praguejs   hNp://localhost:49200   -­‐  Change  some  files   -­‐  Rebuild  &  test   >  docker  build  -­‐t  praguejs   >  docker  run  -­‐p  49200:3333  praguejs 17
  • 18.
    Push  to  producHon   • Tag  image  in  order  to  push  it
 >  docker  tag  praguejs  registry.abtris.cz:5000/praguejs   • Push  image  to  local  registry
 >  docker  push  registry.abtris.cz:5000/praguejs   • On  producHon  server,  pull  image
 >  docker  pull  registry.abtris.cz:5000/praguejs   • Start  new  container  
 >  docker  run  -­‐d  -­‐p  127.0.0.1::3333  <image>   vagrant@precise64:~$  docker  ps   • Change  configuraHon  at  nginx/haproxy  and  restart   CONTAINER  ID                IMAGE                                                                         b2332dffe                      registry.abtris.cz:5000/praguejs:latest     • See  changes  live d45222331                      1b4f43asds   18
  • 19.
  • 20.