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

Introduction à Docker

Introduction à Docker

ubermuda

June 23, 2014
Tweet

More Decks by ubermuda

Other Decks in Programming

Transcript

  1. Introduction à Docker
    Geoffrey Bachelet – @ubermuda

    View Slide

  2. Freelance
    Symfony2
    Devops
    @ubermuda
    Auteur
    Développeur
    Formateur

    View Slide

  3. Container Engine?
    Basé sur les instructions Linux LXC
    Isolation des processus et des ressources
    "chroot" sur-vitaminé / VM super légères

    View Slide

  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

    View Slide

  5. VMs vs Containers
    LXC / Jails / Zones / etc
    Utilise le noyaux de l'hôte
    Démarre en quelques secondes
    Pas de ressources
    Facile à distribuer
    Hypervisor
    Démarre un OS complet
    Démarre en quelques minutes
    Ressources de l'OS invité
    Images de plusieurs Go

    View Slide

  6. Image vs Container

    View Slide

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

    View Slide

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

    View Slide

  9. Créer un container

    View Slide

  10. $  docker  run  -­‐i  -­‐t  stackbrew/ubuntu  /bin/bash  
    !
    [email protected]:/#

    View Slide

  11. Commiter un container

    View Slide

  12. [email protected]:/#  apt-­‐get  install  nginx  
    [email protected]:/#  exit  
    !
    $  docker  ps  -­‐q  -­‐n  1  
    21d86a0b8387  
    !
    $  docker  commit  21d86a0b8387  phptour/nginx  
    240198b750c3cc950c60005d6d24cae4fc2dbcc6c31e274574af68d4a2e8  
    !
    $  docker  images  
    REPOSITORY                TAG                  IMAGE  ID  
    phptour/nginx          latest            240198b750c3

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  16. Exécuter une image

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  25. Exécuter
    Commiter
    Exécuter
    Commiter
    ...
    un container
    une image

    View Slide

  26. View Slide

  27. Dockerfile

    View Slide

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

    View Slide

  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"]

    View Slide

  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"]

    View Slide

  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"]

    View Slide

  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"]

    View Slide

  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"]

    View Slide

  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"]

    View Slide

  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"]

    View Slide

  36. 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"]

    View Slide

  37. 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"]

    View Slide

  38. docker  build  -­‐t  phptour/nginx  -­‐  <  Dockerfile

    View Slide

  39. docker  build  -­‐t  phptour/nginx  -­‐  <  Dockerfile

    View Slide

  40. docker  build  -­‐t  phptour/nginx  -­‐  <  Dockerfile

    View Slide

  41. docker  build  -­‐t  phptour/nginx  -­‐  <  Dockerfile

    View Slide

  42. docker  build  -­‐t  phptour/nginx  -­‐  <  Dockerfile

    View Slide

  43. docker  build  -­‐t  phptour/nginx  -­‐  <  Dockerfile

    View Slide

  44. docker  run  -­‐d  phptour/nginx

    View Slide

  45. Fonctionalités

    View Slide

  46. • Docker CLI
    • run -d, attach, wait, ps, images, rm, rmi, etc
    • Réseau
    • Ambassador, advanced routing, etc
    • Volumes
    • Data containers, bindmounting, etc
    • Docker Index
    • thousands of ready-made images
    • Docker Registry
    • private Docker Index, Docker Hub, etc
    • Remote API
    • dockerode, Docker-PHP, etc

    View Slide

  47. Docker CLI
    • run  [-­‐d] : exécuter un container
    • attach : attacher stdout / stdin
    • ps : lister les containers
    • images : lister les images
    • rm  /  rmi : supprimer des containers / images

    View Slide

  48. Usage:  docker  [OPTIONS]  COMMAND  [arg...]  
     -­‐H=[unix:///var/run/docker.sock]:  tcp://host:port  to  bind/connect  to  or  unix://path/to/socket  to  use  
    !
    A  self-­‐sufficient  runtime  for  linux  containers.  
    !
    Commands:  
           attach        Attach  to  a  running  container  
           build          Build  a  container  from  a  Dockerfile  
           commit        Create  a  new  image  from  a  container's  changes  
           cp                Copy  files/folders  from  the  containers  filesystem  to  the  host  path  
           diff            Inspect  changes  on  a  container's  filesystem  
           events        Get  real  time  events  from  the  server  
           export        Stream  the  contents  of  a  container  as  a  tar  archive  
           history      Show  the  history  of  an  image  
           images        List  images  
           import        Create  a  new  filesystem  image  from  the  contents  of  a  tarball  
           info            Display  system-­‐wide  information  
           inspect      Return  low-­‐level  information  on  a  container  
           kill            Kill  a  running  container  
           load            Load  an  image  from  a  tar  archive  
           login          Register  or  Login  to  the  docker  registry  server  
           logs            Fetch  the  logs  of  a  container  
           port            Lookup  the  public-­‐facing  port  which  is  NAT-­‐ed  to  PRIVATE_PORT  
           ps                List  containers  
           pull            Pull  an  image  or  a  repository  from  the  docker  registry  server  
           push            Push  an  image  or  a  repository  to  the  docker  registry  server  
           restart      Restart  a  running  container  
           rm                Remove  one  or  more  containers  
           rmi              Remove  one  or  more  images  
           run              Run  a  command  in  a  new  container  
           save            Save  an  image  to  a  tar  archive  
           search        Search  for  an  image  in  the  docker  index  
           start          Start  a  stopped  container  
           stop            Stop  a  running  container  
           tag              Tag  an  image  into  a  repository  
           top              Lookup  the  running  processes  of  a  container  
           version      Show  the  docker  version  information  
           wait            Block  until  a  container  stops,  then  print  its  exit  code

    View Slide

  49. Réseau
    Lier des containers entre eux
    "Service Discovery" facilité
    Design pattern "Ambassador" (portabilité)

    View Slide

  50. $  docker  run  -­‐-­‐name  redis  phptour/redis  
    !
    $  docker  run  -­‐-­‐link  redis:db  phptour/symfony2

    View Slide

  51. $  docker  run  -­‐-­‐name  redis  phptour/redis  
    !
    $  docker  run  -­‐-­‐link  redis:db  phptour/symfony2

    View Slide

  52. $  docker  run  -­‐-­‐name  redis  phptour/redis  
    !
    $  docker  run  -­‐-­‐link  redis:db  phptour/symfony2

    View Slide

  53. Volumes
    Comme NFS pour Docker (sauf que ça marche)
    Stocker des données dans des "Data Containers"
    Backup aisé des "Data Containers"

    View Slide

  54. $  docker  run  -­‐-­‐name  data  phptour/data  
    !
    $  docker  run  -­‐-­‐volumes-­‐from  data  -­‐-­‐name  mysql  phptour/mysql

    View Slide

  55. $  docker  run  -­‐-­‐name  data  phptour/data  
    !
    $  docker  run  -­‐-­‐volumes-­‐from  data  -­‐-­‐name  mysql  phptour/mysql

    View Slide

  56. Docker Hub

    View Slide

  57. Docker Hub
    Milliers d'images existantes
    Builds automatisés
    Dépôts privés
    OAuth + API

    View Slide

  58. Docker Remote API
    API (à peu près) REST pour Docker
    !
    Clients tierce-partie
    Dockerode, Docker-PHP, etc
    https://docs.docker.com/reference/api/
    remote_api_client_libraries/

    View Slide

  59. Orchestration

    View Slide

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

    View Slide

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

    View Slide

  62. $  docker  run  -­‐name  data  phptour/data  
    !
    $  docker  run  -­‐-­‐volumes-­‐from  data  -­‐-­‐name  mysql  phptour/mysql  
    !
    $  docker  run  -­‐v  $(pwd):/var/www  -­‐-­‐name  php5  phptour/php5  
    !
    $  docker  run  -­‐p  80:80  -­‐v  $(pwd):/var/www  \  
      -­‐link  php5:php5  \  
      -­‐link  mysql:mysql  \  
      phptour/nginx

    View Slide

  63. Pas natif
    libswarm / libchan
    !
    Beaucoup d'outils tierce-partie :
    !
    https://github.com/marmelab/gaudi
    http://orchardup.github.io/fig/
    http://docs.vagrantup.com/v2/docker/index.html
    ...

    View Slide

  64. Cas d'usage

    View Slide

  65. Environnements de Dev.
    Intégration continue
    Parallélisation de tests automatiques
    Pré-production continue
    Déploiement continu
    Déploiement Green/Blue
    PaaS Privé
    ...

    View Slide

  66. Environnements de Dev.
    Intégration continue
    Parallélisation de tests automatiques
    Pré-production continue
    Déploiement continu
    Déploiement Green/Blue
    PaaS Privé
    ...
    Développer et packager
    votre application Symfony2
    avec Docker et Vagrant
    Demain 13:45, Salle 3

    View Slide

  67. Environnements de Dev.
    Intégration continue
    Parallélisation de tests automatiques
    Pré-production continue
    Déploiement continu
    Déploiement Green/Blue
    PaaS Privé
    ...
    drone.io

    View Slide

  68. Environnements de Dev.
    Intégration continue
    Parallélisation de tests automatiques
    Pré-production continue
    Déploiement continu
    Déploiement Green/Blue
    PaaS Privé
    ...
    stage1.io

    View Slide

  69. Environnements de Dev.
    Intégration continue
    Parallélisation de tests automatiques
    Pré-production continue
    Déploiement continu
    Déploiement Green/Blue
    PaaS Privé
    ...
    wercker.com

    View Slide

  70. PaaS Privé
    Flynn
    Dokku
    Mesos
    Octohost
    opdemand
    tsuru
    cocaine
    openshift
    Atomic
    Deis
    ...

    View Slide

  71. Merci !
    https://speackerdeck.com/ubermuda/introduction-a-docker
    Geoffrey Bachelet – @ubermuda
    http://stage1.io/

    View Slide