Slide 1

Slide 1 text

Introduction à Docker Geoffrey Bachelet – @ubermuda

Slide 2

Slide 2 text

Freelance Symfony2 Devops @ubermuda Auteur Développeur Formateur

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

Image vs Container

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

Créer un container

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

Commiter un container

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

Exécuter une image

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

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

Slide 20

Slide 20 text

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

Slide 21

Slide 21 text

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

Slide 22

Slide 22 text

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

Slide 23

Slide 23 text

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

Slide 24

Slide 24 text

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

Slide 25

Slide 25 text

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

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

Dockerfile

Slide 28

Slide 28 text

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

Slide 29

Slide 29 text

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

Slide 30

Slide 30 text

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

Slide 31

Slide 31 text

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

Slide 32

Slide 32 text

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

Slide 33

Slide 33 text

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

Slide 34

Slide 34 text

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

Slide 35

Slide 35 text

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

Slide 36

Slide 36 text

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

Slide 37

Slide 37 text

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

Slide 38

Slide 38 text

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

Slide 39

Slide 39 text

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

Slide 40

Slide 40 text

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

Slide 41

Slide 41 text

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

Slide 42

Slide 42 text

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

Slide 43

Slide 43 text

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

Slide 44

Slide 44 text

docker  run  -­‐d  phptour/nginx

Slide 45

Slide 45 text

Fonctionalités

Slide 46

Slide 46 text

• 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

Slide 47

Slide 47 text

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

Slide 48

Slide 48 text

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

Slide 49

Slide 49 text

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

Slide 50

Slide 50 text

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

Slide 51

Slide 51 text

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

Slide 52

Slide 52 text

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

Slide 53

Slide 53 text

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

Slide 54

Slide 54 text

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

Slide 55

Slide 55 text

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

Slide 56

Slide 56 text

Docker Hub

Slide 57

Slide 57 text

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

Slide 58

Slide 58 text

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/

Slide 59

Slide 59 text

Orchestration

Slide 60

Slide 60 text

Host OS THE INTERNET container nginx mysql php5-fpm

Slide 61

Slide 61 text

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

Slide 62

Slide 62 text

$  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

Slide 63

Slide 63 text

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 ...

Slide 64

Slide 64 text

Cas d'usage

Slide 65

Slide 65 text

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

Slide 66

Slide 66 text

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

Slide 67

Slide 67 text

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

Slide 68

Slide 68 text

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

Slide 69

Slide 69 text

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

Slide 70

Slide 70 text

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

Slide 71

Slide 71 text

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