Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Meetup Docker 101

Meetup Docker 101

A gentle introduction to Docker

88b8138397e1d1441f4e4a54348bde09?s=128

ubermuda

May 28, 2014
Tweet

Transcript

  1. Docker 101 Geoffrey Bachelet –@ubermuda

  2. Who's talking? • Geoffrey Bachelet • Stage1.io : continuous staging

    • Gustave.io : interactive staging • Freelance Developer / Trainer @ubermuda
  3. Container Engine? Based on the Linux kernel's LXC instructions Processes

    and resources isolation "chroot" on steroids / super lightweight VMs
  4. Host OS Hypervisor Guest OS Guest OS Guest OS Guest

    OS App App App App Host OS Docker + LXC App App App App VMs vs Containers
  5. VMs vs Containers LXC / Jails / Zones / etc

    Uses the host's kernel Boots in seconds 0 overhead (almost) Easy to pass around Hypervisor Boots a complete OS Boots in minutes Guest OS' overhead Several Go images
  6. Image vs Container

  7. credit: http:/ /docs.docker.io/en/latest/terms/image/ Image

  8. Container credit: http:/ /docs.docker.io/en/latest/terms/image/

  9. Create a container

  10. $  docker  run  -­‐i  -­‐t  stackbrew/ubuntu  /bin/bash   ! root@21d86a0b8387:/#

  11. Commit the container

  12. root@21d86a0b8387:/#  apt-­‐get  install  nginx   root@21d86a0b8387:/#  exit   ! $

     docker  ps  -­‐q  -­‐n  1   21d86a0b8387   ! $  docker  commit  21d86a0b8387  sflive/nginx   240198b750c3cc950c60005d6d24cae4fc2dbcc6c31e274574af68d4a2e8   ! $  docker  images   REPOSITORY            TAG                  IMAGE  ID   sflive/nginx          latest            240198b750c3
  13. root@21d86a0b8387:/#  apt-­‐get  install  nginx   root@21d86a0b8387:/#  exit   ! $

     docker  ps  -­‐q  -­‐n  1   21d86a0b8387   ! $  docker  commit  21d86a0b8387  sflive/nginx   240198b750c3cc950c60005d6d24cae4fc2dbcc6c31e274574af68d4a2e8   ! $  docker  images   REPOSITORY            TAG                  IMAGE  ID   sflive/nginx          latest            240198b750c3
  14. root@21d86a0b8387:/#  apt-­‐get  install  nginx   root@21d86a0b8387:/#  exit   ! $

     docker  ps  -­‐q  -­‐n  1   21d86a0b8387   ! $  docker  commit  21d86a0b8387  sflive/nginx   240198b750c3cc950c60005d6d24cae4fc2dbcc6c31e274574af68d4a2e8   ! $  docker  images   REPOSITORY            TAG                  IMAGE  ID   sflive/nginx          latest            240198b750c3
  15. root@21d86a0b8387:/#  apt-­‐get  install  nginx   root@21d86a0b8387:/#  exit   ! $

     docker  ps  -­‐q  -­‐n  1   21d86a0b8387   ! $  docker  commit  21d86a0b8387  sflive/nginx   240198b750c3cc950c60005d6d24cae4fc2dbcc6c31e274574af68d4a2e8   ! $  docker  images   REPOSITORY            TAG                  IMAGE  ID   sflive/nginx          latest            240198b750c3
  16. Run the image

  17. $  docker  run  -­‐p  80  sflive/nginx  nginx  -­‐g  'daemon  off;'

  18. $  docker  run  -­‐p  80  sflive/nginx  nginx  -­‐g  'daemon  off;'

  19. $  docker  run  -­‐p  80  sflive/nginx  nginx  -­‐g  'daemon  off;'

  20. $  docker  run  -­‐p  80  sflive/nginx  nginx  -­‐g  'daemon  off;'

  21. $  docker  run  -­‐p  80  sflive/nginx  nginx  -­‐g  'daemon  off;'

  22. $  docker  run  -­‐p  80  sflive/nginx  nginx  -­‐g  'daemon  off;'

  23. $  docker  ps   CONTAINER  ID    ...    PORTS

      923cb190dbc3    ...    0.0.0.0:49155-­‐>80/tcp   ! $  curl  http://localhost:49155   <html>   <head>   <title>Welcome  to  nginx!</title>   ...
  24. $  docker  ps   CONTAINER  ID    ...    PORTS

      923cb190dbc3    ...    0.0.0.0:49155-­‐>80/tcp   ! $  curl  http://localhost:49155   <html>   <head>   <title>Welcome  to  nginx!</title>   ...
  25. Dockerfile

  26. credit: http:/ /docs.docker.io/en/latest/terms/image/

  27. FROM  stackbrew/ubuntu   ENV  DEBIAN_FRONTEND  noninteractive   RUN  apt-­‐get  install

     -­‐y  nginx   ADD  nginx.conf  /etc/nginx/nginx.conf   EXPOSE  80   VOLUME  ["/var/www"]   CMD  ["-­‐g",  "daemon  off;"]   ENTRYPOINT  ["nginx"]
  28. FROM  stackbrew/ubuntu   ENV  DEBIAN_FRONTEND  noninteractive   RUN  apt-­‐get  install

     -­‐y  nginx   ADD  nginx.conf  /etc/nginx/nginx.conf   EXPOSE  80   VOLUME  ["/var/www"]   CMD  ["-­‐g",  "daemon  off;"]   ENTRYPOINT  ["nginx"]
  29. FROM  stackbrew/ubuntu   ENV  DEBIAN_FRONTEND  noninteractive   RUN  apt-­‐get  install

     -­‐y  nginx   ADD  nginx.conf  /etc/nginx/nginx.conf   EXPOSE  80   VOLUME  ["/var/www"]   CMD  ["-­‐g",  "daemon  off;"]   ENTRYPOINT  ["nginx"]
  30. FROM  stackbrew/ubuntu   ENV  DEBIAN_FRONTEND  noninteractive   RUN  apt-­‐get  install

     -­‐y  nginx   ADD  nginx.conf  /etc/nginx/nginx.conf   EXPOSE  80   VOLUME  ["/var/www"]   CMD  ["-­‐g",  "daemon  off;"]   ENTRYPOINT  ["nginx"]
  31. FROM  stackbrew/ubuntu   ENV  DEBIAN_FRONTEND  noninteractive   RUN  apt-­‐get  install

     -­‐y  nginx   ADD  nginx.conf  /etc/nginx/nginx.conf   EXPOSE  80   VOLUME  ["/var/www"]   CMD  ["-­‐g",  "daemon  off;"]   ENTRYPOINT  ["nginx"]
  32. FROM  stackbrew/ubuntu   ENV  DEBIAN_FRONTEND  noninteractive   RUN  apt-­‐get  install

     -­‐y  nginx   ADD  nginx.conf  /etc/nginx/nginx.conf   EXPOSE  80   VOLUME  ["/var/www"]   CMD  ["-­‐g",  "daemon  off;"]   ENTRYPOINT  ["nginx"]
  33. FROM  stackbrew/ubuntu   ENV  DEBIAN_FRONTEND  noninteractive   RUN  apt-­‐get  install

     -­‐y  nginx   ADD  nginx.conf  /etc/nginx/nginx.conf   EXPOSE  80   VOLUME  ["/var/www"]   CMD  ["-­‐g",  "daemon  off;"]   ENTRYPOINT  ["nginx"]
  34. FROM  stackbrew/ubuntu   ENV  DEBIAN_FRONTEND  noninteractive   RUN  apt-­‐get  install

     -­‐y  nginx   ADD  nginx.conf  /etc/nginx/nginx.conf   EXPOSE  80   VOLUME  ["/var/www"]   CMD  ["-­‐g",  "daemon  off;"]   ENTRYPOINT  ["nginx"]
  35. FROM  stackbrew/ubuntu   ENV  DEBIAN_FRONTEND  noninteractive   RUN  apt-­‐get  install

     -­‐y  nginx   ADD  nginx.conf  /etc/nginx/nginx.conf   EXPOSE  80   VOLUME  ["/var/www"]   CMD  ["-­‐g",  "daemon  off;"]   ENTRYPOINT  ["nginx"]
  36. Features

  37. • Docker CLI • run -d, attach, wait, ps, images,

    rm, rmi, etc • Networking • Ambassador, advanced routing, etc • Volumes • Data containers, bindmounting, etc • Docker Index • thousands of ready-made images • Docker Registry • private Docker Index • Remote API • dockerode, Docker-PHP, etc
  38. Docker CLI • run  [-­‐d] : execute a container •

    attach : attach stdout • ps : list running containers • images : list existing images • rm  /  rmi : delete containers / images
  39. Networking Link containers together Easy service discovery Ambassador pattern (service

    portability)
  40. Volumes Like NFS for docker (except it works) Store data

    in data containers Easily backup data containers
  41. Docker Index + Registry Thousands of ready-made images Private registry

  42. Docker Remote API Rest(-ish) HTTP API for Docker ! Third

    party client libraries: dockerode, Docker-php, etc
  43. Orchestration

  44. Host OS THE INTERNET container nginx mysql php5-fpm

  45. Host OS THE INTERNET nginx mysql php5-fpm /var/www /var/lib/mysql

  46. Not built-in Lots of third-party tools ! maestro-ng, Fig, Gaudi,

    etc.
  47. Pets vs Cattle

  48. Use cases

  49. Dev. environments Continuous integration Continuous deployment 0 downtime deployment Private

    PaaS
  50. Thanks! https://speackerdeck.com/ubermuda/meetup-docker-101 Geoffrey Bachelet – @ubermuda