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

A multi-container Symfony2 setup with Docker

A multi-container Symfony2 setup with Docker

ubermuda

April 08, 2014
Tweet

More Decks by ubermuda

Other Decks in Programming

Transcript

  1. Geoffrey Bachelet – @ubermuda
    A multi-container Symfony2 setup
    with Docker.

    View Slide

  2. Container Engine?
    Based on the Linux kernel's LXC instructions
    Processes and resources isolation
    "chroot" on steroids / super lightweight VMs

    View Slide

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

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

    View Slide

  6. Install

    View Slide

  7. $  echo  "deb  https://get.docker.io/ubuntu  docker  main"  \  
      >  /etc/apt/sources.list.d/docker.list  
    $  apt-­‐get  update  
    $  apt-­‐get  install  lxc-­‐docker

    View Slide

  8. Create a container

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  17. Commit the container

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  23. Run the image

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  27. Dockerfile

    View Slide

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

    View Slide

  29. $  cd  /project  
    project  $  bin/start  
    Loading  composer  repositories  with  package  information  
    Installing  dependencies  (including  require-­‐dev)  from  lock  file  
    ...

    View Slide

  30. View Slide

  31. FROM  sflive/base  
    ENV  DEBIAN_FRONTEND  noninteractive  
    !
    RUN  apt-­‐get  install  -­‐y  \  
           daemontools  curl  nginx  mysql-­‐server  redis-­‐server  \  
           php5-­‐cli  php5-­‐json  php5-­‐fpm  php5-­‐intl  php5-­‐mysqlnd  
    !
    RUN  curl  -­‐sS  https://getcomposer.org/installer  |  php  
    RUN  mv  composer.phar  /usr/local/bin/composer  
    !
    RUN  echo  "daemonize=no"  >  /etc/php5/fpm/pool.d/daemonize.conf  
    RUN  echo  "\ndaemon  off;"  >>  /etc/nginx/nginx.conf  
    !
    ADD  vhost.conf  /etc/nginx/sites-­‐enabled/default  
    ADD  php.ini  /etc/php5/fpm/php.ini  
    ADD  php.ini  /etc/php5/cli/php.ini  
    ADD  my.cnf  /etc/mysql/my.cnf  
    ADD  services/  /srv/services  
    ADD  entrypoint.sh  /usr/local/bin/entrypoint.sh  
    !
    EXPOSE  80  
    !
    ENTRYPOINT  ["/usr/local/bin/entrypoint.sh"]

    View Slide

  32. FROM  sflive/base  
    ENV  DEBIAN_FRONTEND  noninteractive

    View Slide

  33. RUN  apt-­‐get  install  -­‐y  \  
           daemontools  curl  nginx  mysql-­‐server  redis-­‐server  \  
           php5-­‐cli  php5-­‐json  php5-­‐fpm  php5-­‐intl  php5-­‐mysqlnd  
    !
    RUN  curl  -­‐sS  https://getcomposer.org/installer  |  php  
    RUN  mv  composer.phar  /usr/local/bin/composer

    View Slide

  34. RUN  echo  "daemonize=no"  \  
      >  /etc/php5/fpm/pool.d/daemonize.conf  
    !
    RUN  echo  "\ndaemon  off;"  \  
      >>  /etc/nginx/nginx.conf

    View Slide

  35. ADD  vhost.conf  /etc/nginx/sites-­‐enabled/default  
    ADD  php.ini  /etc/php5/fpm/php.ini  
    ADD  php.ini  /etc/php5/cli/php.ini  
    ADD  my.cnf  /etc/mysql/my.cnf  
    ADD  services/  /srv/services  
    !
    ADD  entrypoint.sh  /usr/local/bin/entrypoint.sh

    View Slide

  36. ADD  vhost.conf  /etc/nginx/sites-­‐enabled/default  
    ADD  php.ini  /etc/php5/fpm/php.ini  
    ADD  php.ini  /etc/php5/cli/php.ini  
    ADD  my.cnf  /etc/mysql/my.cnf  
    ADD  services/  /srv/services  
    !
    ADD  entrypoint.sh  /usr/local/bin/entrypoint.sh

    View Slide

  37. EXPOSE  80  
    !
    ENTRYPOINT  ["/usr/local/bin/entrypoint.sh"]

    View Slide

  38. symfony2  
    ├──  Dockerfile  
    ├──  entrypoint.sh  
    ├──  my.cnf  
    ├──  php.ini  
    ├──  services  
    │      ├──  mysql  
    │      │      └──  run  
    │      ├──  nginx  
    │      │      └──  run  
    │      └──  php5-­‐fpm  
    │              └──  run  
    └──  vhost.conf

    View Slide

  39. symfony2  
    ├──  Dockerfile  
    ├──  entrypoint.sh  
    ├──  my.cnf  
    ├──  php.ini  
    ├──  services  
    │      ├──  mysql  
    │      │      └──  run  
    │      ├──  nginx  
    │      │      └──  run  
    │      └──  php5-­‐fpm  
    │              └──  run  
    └──  vhost.conf

    View Slide

  40. symfony2  
    ├──  Dockerfile  
    ├──  entrypoint.sh  
    ├──  my.cnf  
    ├──  php.ini  
    ├──  services  
    │      ├──  mysql  
    │      │      └──  run  
    │      ├──  nginx  
    │      │      └──  run  
    │      └──  php5-­‐fpm  
    │              └──  run  
    └──  vhost.conf
    #!/bin/bash  
    exec  /usr/bin/mysqld_safe
    #!/bin/bash  
    exec  /usr/bin/nginx
    #!/bin/bash  
    exec  /usr/sbin/php5-­‐fpm

    View Slide

  41. symfony2  
    ├──  Dockerfile  
    ├──  entrypoint.sh  
    ├──  my.cnf  
    ├──  php.ini  
    ├──  services  
    │      ├──  mysql  
    │      │      └──  run  
    │      ├──  nginx  
    │      │      └──  run  
    │      └──  php5-­‐fpm  
    │              └──  run  
    └──  vhost.conf
    #!/bin/bash  -­‐e  
    !
    if  [  !  -­‐d  /var/www  ];  then  
           echo  'No  application  found  in  /var/www'  
           exit  1;  
    fi  
    !
    cd  /var/www  
    !
    if  [  !  -­‐d  vendor  ];  then  
           composer  install  
    fi  
    !
    if  [  -­‐f  ./init.sh  ];  then  
           ./init.sh  
    fi  
    !
    exec  svscan  /srv/services

    View Slide

  42. symfony2  
    ├──  Dockerfile  
    ├──  entrypoint.sh  
    ├──  my.cnf  
    ├──  php.ini  
    ├──  services  
    │      ├──  mysql  
    │      │      └──  run  
    │      ├──  nginx  
    │      │      └──  run  
    │      └──  php5-­‐fpm  
    │              └──  run  
    └──  vhost.conf
    #!/bin/bash  -­‐e  
    !
    if  [  !  -­‐d  /var/www  ];  then  
           echo  'No  application  found  in  /var/www'  
           exit  1;  
    fi  
    !
    cd  /var/www  
    !
    if  [  !  -­‐d  vendor  ];  then  
           composer  install  
    fi  
    !
    if  [  -­‐f  ./init.sh  ];  then  
           ./init.sh  
    fi  
    !
    exec  svscan  /srv/services

    View Slide

  43. symfony2  
    ├──  Dockerfile  
    ├──  entrypoint.sh  
    ├──  my.cnf  
    ├──  php.ini  
    ├──  services  
    │      ├──  mysql  
    │      │      └──  run  
    │      ├──  nginx  
    │      │      └──  run  
    │      └──  php5-­‐fpm  
    │              └──  run  
    └──  vhost.conf
    #!/bin/bash  -­‐e  
    !
    if  [  !  -­‐d  /var/www  ];  then  
           echo  'No  application  found  in  /var/www'  
           exit  1;  
    fi  
    !
    cd  /var/www  
    !
    if  [  !  -­‐d  vendor  ];  then  
           composer  install  
    fi  
    !
    if  [  -­‐f  ./init.sh  ];  then  
           ./init.sh  
    fi  
    !
    exec  svscan  /srv/services

    View Slide

  44. symfony2  
    ├──  Dockerfile  
    ├──  entrypoint.sh  
    ├──  my.cnf  
    ├──  php.ini  
    ├──  services  
    │      ├──  mysql  
    │      │      └──  run  
    │      ├──  nginx  
    │      │      └──  run  
    │      └──  php5-­‐fpm  
    │              └──  run  
    └──  vhost.conf
    #!/bin/bash  -­‐e  
    !
    if  [  !  -­‐d  /var/www  ];  then  
           echo  'No  application  found  in  /var/www'  
           exit  1;  
    fi  
    !
    cd  /var/www  
    !
    if  [  !  -­‐d  vendor  ];  then  
           composer  install  
    fi  
    !
    if  [  -­‐f  ./init.sh  ];  then  
           ./init.sh  
    fi  
    !
    exec  svscan  /srv/services

    View Slide

  45. symfony2  
    ├──  Dockerfile  
    ├──  entrypoint.sh  
    ├──  my.cnf  
    ├──  php.ini  
    ├──  services  
    │      ├──  mysql  
    │      │      └──  run  
    │      ├──  nginx  
    │      │      └──  run  
    │      └──  php5-­‐fpm  
    │              └──  run  
    └──  vhost.conf
    #!/bin/bash  -­‐e  
    !
    if  [  !  -­‐d  /var/www  ];  then  
           echo  'No  application  found  in  /var/www'  
           exit  1;  
    fi  
    !
    cd  /var/www  
    !
    if  [  !  -­‐d  vendor  ];  then  
           composer  install  
    fi  
    !
    if  [  -­‐f  ./init.sh  ];  then  
           ./init.sh  
    fi  
    !
    exec  svscan  /srv/services

    View Slide

  46. $  docker  build  -­‐t  sflive/symfony2  symfony2/

    View Slide

  47. $  docker  build  -­‐t  sflive/symfony2  symfony2/

    View Slide

  48. $  docker  run  \  
      -­‐p  8000:80  \  
      -­‐v  /project:/var/www  \  
      sflive/symfony2

    View Slide

  49. $  docker  run  \  
      -­‐p  8000:80  \  
      -­‐v  /project:/var/www  \  
      sflive/symfony2

    View Slide

  50. $  docker  run  \  
      -­‐p  8000:80  \  
      -­‐v  /project:/var/www  \  
      sflive/symfony2

    View Slide

  51. #!/bin/bash  
    docker  run  -­‐d  \  
      -­‐v  $(pwd):/var/www  \  
      -­‐p  80:80  \  
      -­‐-­‐cidfile  app/cache/docker.cid  \  
      sflive/symfony2
    bin/start

    View Slide

  52. #!/bin/bash  
    docker  stop  $(cat  app/cache/docker.cid)
    bin/stop

    View Slide

  53. $  cd  /project  
    project  $  bin/start  
    Loading  composer  repositories  with  package  information  
    Installing  dependencies  (including  require-­‐dev)  from  lock  file  
    ...

    View Slide

  54. View Slide

  55. View Slide

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

    View Slide

  57. Multi-container setup

    View Slide

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

    View Slide

  59. Containers links

    View Slide

  60. $  docker  run  -­‐-­‐name  redis  sflive/redis  
    !
    $  docker  run  -­‐-­‐link  redis:foo  sflive/symfony2

    View Slide

  61. $  docker  run  -­‐-­‐name  redis  sflive/redis  
    !
    $  docker  run  -­‐-­‐link  redis:foo  sflive/symfony2

    View Slide

  62. $  docker  run  -­‐-­‐name  redis  sflive/redis  
    !
    $  docker  run  -­‐-­‐link  redis:foo  sflive/symfony2

    View Slide

  63. $  printenv  |  grep  -­‐E  '^FOO'  
    FOO_PORT=tcp://172.17.0.44:6379  
    FOO_PORT_6379_TCP_PROTO=tcp  
    FOO_PORT_6379_TCP_PORT=6379  
    FOO_PORT_6379_TCP=tcp://172.17.0.44:6379  
    FOO_NAME=/crimson_squirrel9/redis  
    FOO_PORT_6379_TCP_ADDR=172.17.0.44

    View Slide

  64. $  printenv  |  grep  -­‐E  '^FOO'  
    FOO_PORT=tcp://172.17.0.44:6379  
    FOO_PORT_6379_TCP_PROTO=tcp  
    FOO_PORT_6379_TCP_PORT=6379  
    FOO_PORT_6379_TCP=tcp://172.17.0.44:6379  
    FOO_NAME=/crimson_squirrel9/redis  
    FOO_PORT_6379_TCP_ADDR=172.17.0.44

    View Slide

  65. imports:  
      -­‐  {  resource:  parameters.php  }
    app/config/config.yml

    View Slide

  66. app/config/parameters.php
    !
    $container-­‐>setParameter(  
      'redis_host',  
      getenv('FOO_PORT_6379_TCP_ADDR')  
    );

    View Slide

  67. .  
    ├──  base  
    │      └──  Dockerfile  
    ├──  data  
    │      └──  Dockerfile  
    ├──  mysql  
    │      ├──  Dockerfile  
    │      ├──  entrypoint.sh  
    │      └──  my.cnf  
    ├──  nginx  
    │      ├──  Dockerfile  
    │      ├──  entrypoint.sh  
    │      └──  vhost.conf  
    └──  php5  
           ├──  Dockerfile  
           └──  php.ini

    View Slide

  68. .  
    ├──  base  
    │      └──  Dockerfile  
    ├──  data  
    │      └──  Dockerfile  
    ├──  mysql  
    │      ├──  Dockerfile  
    │      ├──  entrypoint.sh  
    │      └──  my.cnf  
    ├──  nginx  
    │      ├──  Dockerfile  
    │      ├──  entrypoint.sh  
    │      └──  vhost.conf  
    └──  php5  
           ├──  Dockerfile  
           └──  php.ini

    View Slide

  69. .  
    ├──  base  
    │      └──  Dockerfile  
    ├──  data  
    │      └──  Dockerfile  
    ├──  mysql  
    │      ├──  Dockerfile  
    │      ├──  entrypoint.sh  
    │      └──  my.cnf  
    ├──  nginx  
    │      ├──  Dockerfile  
    │      ├──  entrypoint.sh  
    │      └──  vhost.conf  
    └──  php5  
           ├──  Dockerfile  
           └──  php.ini
    FROM  sflive/base  
    VOLUME  ["/var/lib/mysql"]  
    ENTRYPOINT  ["true"]

    View Slide

  70. .  
    ├──  base  
    │      └──  Dockerfile  
    ├──  data  
    │      └──  Dockerfile  
    ├──  mysql  
    │      ├──  Dockerfile  
    │      ├──  entrypoint.sh  
    │      └──  my.cnf  
    ├──  nginx  
    │      ├──  Dockerfile  
    │      ├──  entrypoint.sh  
    │      └──  vhost.conf  
    └──  php5  
           ├──  Dockerfile  
           └──  php.ini
    FROM  sflive/base  
    VOLUME  ["/var/lib/mysql"]  
    ENTRYPOINT  ["true"]

    View Slide

  71. .  
    ├──  base  
    │      └──  Dockerfile  
    ├──  data  
    │      └──  Dockerfile  
    ├──  mysql  
    │      ├──  Dockerfile  
    │      ├──  entrypoint.sh  
    │      └──  my.cnf  
    ├──  nginx  
    │      ├──  Dockerfile  
    │      ├──  entrypoint.sh  
    │      └──  vhost.conf  
    └──  php5  
           ├──  Dockerfile  
           └──  php.ini
    #!/bin/bash  
    !
    if  [  !  -­‐f  /var/lib/mysql/ibdata1  ];  then  
           mysql_install_db  >  /dev/null  
    fi  
    !
    exec  /usr/bin/mysqld_safe

    View Slide

  72. .  
    ├──  base  
    │      └──  Dockerfile  
    ├──  data  
    │      └──  Dockerfile  
    ├──  mysql  
    │      ├──  Dockerfile  
    │      ├──  entrypoint.sh  
    │      └──  my.cnf  
    ├──  nginx  
    │      ├──  Dockerfile  
    │      ├──  entrypoint.sh  
    │      └──  vhost.conf  
    └──  php5  
           ├──  Dockerfile  
           └──  php.ini
    #!/bin/bash  
    !
    if  [  !  -­‐f  /var/lib/mysql/ibdata1  ];  then  
           mysql_install_db  >  /dev/null  
    fi  
    !
    exec  /usr/bin/mysqld_safe

    View Slide

  73. .  
    ├──  base  
    │      └──  Dockerfile  
    ├──  data  
    │      └──  Dockerfile  
    ├──  mysql  
    │      ├──  Dockerfile  
    │      ├──  entrypoint.sh  
    │      └──  my.cnf  
    ├──  nginx  
    │      ├──  Dockerfile  
    │      ├──  entrypoint.sh  
    │      └──  vhost.conf  
    └──  php5  
           ├──  Dockerfile  
           └──  php.ini
    bind-­‐address  =  0.0.0.0

    View Slide

  74. .  
    ├──  base  
    │      └──  Dockerfile  
    ├──  data  
    │      └──  Dockerfile  
    ├──  mysql  
    │      ├──  Dockerfile  
    │      ├──  entrypoint.sh  
    │      └──  my.cnf  
    ├──  nginx  
    │      ├──  Dockerfile  
    │      ├──  entrypoint.sh  
    │      └──  vhost.conf  
    └──  php5  
           ├──  Dockerfile  
           └──  php.ini
    #!/bin/bash  
    for  env  in  $(printenv);  do  
           IFS==  read  KEY  VALUE  <<<  "$env"  
           sed  \  
        -­‐e  "s,\${${KEY}},${VALUE},g"  \  
        -­‐i  /etc/nginx/sites-­‐enabled/default  
    done;  
    !
    exec  /usr/sbin/nginx

    View Slide

  75. .  
    ├──  base  
    │      └──  Dockerfile  
    ├──  data  
    │      └──  Dockerfile  
    ├──  mysql  
    │      ├──  Dockerfile  
    │      ├──  entrypoint.sh  
    │      └──  my.cnf  
    ├──  nginx  
    │      ├──  Dockerfile  
    │      ├──  entrypoint.sh  
    │      └──  vhost.conf  
    └──  php5  
           ├──  Dockerfile  
           └──  php.ini
    location  ~  [^/]\.php(/|$)  {  
           fastcgi_pass  ${PHP5_PORT_9000_TCP_ADDR}:9000;  
           include  fastcgi_params;  
    }

    View Slide

  76. .  
    ├──  base  
    │      └──  Dockerfile  
    ├──  data  
    │      └──  Dockerfile  
    ├──  mysql  
    │      ├──  Dockerfile  
    │      ├──  entrypoint.sh  
    │      └──  my.cnf  
    ├──  nginx  
    │      ├──  Dockerfile  
    │      ├──  entrypoint.sh  
    │      └──  vhost.conf  
    └──  php5  
           ├──  Dockerfile  
           └──  php.ini
    location  ~  [^/]\.php(/|$)  {  
           fastcgi_pass  ${PHP5_PORT_9000_TCP_ADDR}:9000;  
           include  fastcgi_params;  
    }

    View Slide

  77. .  
    ├──  base  
    │      └──  Dockerfile  
    ├──  data  
    │      └──  Dockerfile  
    ├──  mysql  
    │      ├──  Dockerfile  
    │      ├──  entrypoint.sh  
    │      └──  my.cnf  
    ├──  nginx  
    │      ├──  Dockerfile  
    │      ├──  entrypoint.sh  
    │      └──  vhost.conf  
    └──  php5  
           ├──  Dockerfile  
           └──  php.ini
    RUN  sed  \  
      -­‐e  "s,127.0.0.1:9000,9000,"  \  
      -­‐i  /etc/php5/fpm/pool.d/www.conf

    View Slide

  78. .  
    ├──  base  
    │      └──  Dockerfile  
    ├──  data  
    │      └──  Dockerfile  
    ├──  mysql  
    │      ├──  Dockerfile  
    │      ├──  entrypoint.sh  
    │      └──  my.cnf  
    ├──  nginx  
    │      ├──  Dockerfile  
    │      ├──  entrypoint.sh  
    │      └──  vhost.conf  
    └──  php5  
           ├──  Dockerfile  
           └──  php.ini
    RUN  sed  \  
      -­‐e  "s,127.0.0.1:9000,9000,"  \  
      -­‐i  /etc/php5/fpm/pool.d/www.conf

    View Slide

  79. $  docker  build  -­‐t  sflive/base  base/  
    $  docker  build  -­‐t  sflive/data  data/  
    $  docker  build  -­‐t  sflive/mysql  mysql/  
    $  docker  build  -­‐t  sflive/nginx  nginx/  
    $  docker  build  -­‐t  sflive/php5  php5/

    View Slide

  80. #!/bin/bash  -­‐e  
    for  name  in  $(find  -­‐maxdepth  1  !  -­‐path  .  -­‐type  d);  do  
           docker  build  -­‐t  sflive/$(basename  $name)  -­‐-­‐rm  $name  
    done;

    View Slide

  81. View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  85. View Slide

  86. View Slide

  87. And more!
    • docker run -d, attach, logs, top, ...
    • Orchestration (Gaudi, Fig, ...)
    • Docker Index
    • Docker Remote API (dockerode, Docker-PHP, ...)
    • Dockerfile: USER, WORKDIR, ONBUILD, ...
    • ...

    View Slide

  88. Recap.
    • Image: like a VM image. Contains the hard-drive
    (rootfs) and some configuration.
    • Container: a running instance of an image.

    View Slide

  89. • You can commit a terminated container, and you get
    a re-usable image representing the state of that
    container.
    • Volumes are like shared directories. Containers can
    share zero or many volumes.
    • Containers can be linked to one another.
    Recap.

    View Slide

  90. Thanks!
    https://github.com/ubermuda/sflive-docker/
    Geoffrey Bachelet – @ubermuda

    View Slide