Slide 1

Slide 1 text

Docker, c'est bonheur

Slide 2

Slide 2 text

Qui je suis ● Alexandre Salomé, développeur (180 mois) ● Consultant technique chez SensioLabs (66 mois) ● En mission chez Auchan e-commerce France (7 mois) – Environnement totalement dockerisé – Bientôt les serveurs de qualification – Dans 3 ans en production ?

Slide 3

Slide 3 text

Docker et vous ?

Slide 4

Slide 4 text

Sommaire ● Présentation ● Utilisation – Dockerfile – Commandes usuelles – Registry – Volumes – Port mapping – Links ● Outils – Fig – Baseimage – Boot2Docker – Flynn

Slide 5

Slide 5 text

Présentation de Docker Les grandes idées

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

Avantages ● Exécution rapide, isolée et transportable ● Mise en commun des ressources

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

Show time ! La différence du dossier /etc entre : - Ubuntu 14.10 - Ubuntu 12.10 docker run ubuntu:14.10 ls /etc > etc-14.10 docker run ubuntu:12.10 ls /etc > etc-12.10 meld etc-14.10 etc-12.10

Slide 10

Slide 10 text

Utilisation Commandes usuelles

Slide 11

Slide 11 text

Commandes usuelles $ docker run --name=mon_redis redis Donner un nom à son conteneur avec --name : docker run redis docker run ubuntu:14.10 ls /etc

Slide 12

Slide 12 text

Commandes usuelles $ docker ps CONTAINER ID IMAGE CREATED STATUS NAMES eb232dde2f79 redis:latest 3 seconds ago Up 2 seconds mon_redis $ docker ps -a CONTAINER ID IMAGE CREATED STATUS PORTS NAMES eb232dde2f79 redis:latest 2 minutes ago Up 2 minutes 6379/tcp mon_redis b715035816d7 redis:latest 4 minutes ago Exited (0) 4 minutes ago sharp_wozniak

Slide 13

Slide 13 text

Commandes usuelles $ docker logs mon_redis [1] 14 Jan 19:35:02.096 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf _._ _.-``__ ''-._ _.-`` `. `_. ''-._ Redis 2.8.17 (00000000/0) 64 bit .-`` .-```. ```\/ _.,_ ''-._ ( ' , .-` | `, ) Running in stand alone mode |`-._`-...-` __...-.``-._|'` _.-'| Port: 6379 | `-._ `._ / _.-' | PID: 1 `-._ `-._ `-./ _.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | http://redis.io `-._ `-._`-.__.-'_.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | `-._ `-._`-.__.-'_.-' _.-' `-._ `-.__.-' _.-' `-._ _.-' `-.__.-'

Slide 14

Slide 14 text

Commandes usuelles $ docker inspect mon_redis # ... "Created": "2015-01-14T19:35:01.710341398Z", "Id": "eb232dde2f79741d01d3259566bae6150e5846b3e2e9208a9e6e0897084a80c4", "Image": "3ce54e911389a2b08207b0a4d01c3131ce01b617ecc1c248f6d81ffdbebd628d", "State": { "ExitCode": 0, "FinishedAt": "0001-01-01T00:00:00Z", "Paused": false, "Pid": 4362, "Restarting": false, "Running": true, "StartedAt": "2015-01-14T19:35:02.053470372Z" # ... $ docker inspect -f="{{ .NetworkSettings.IPAddress }}" mon_redis 172.17.0.3

Slide 15

Slide 15 text

Commandes usuelles $ docker diff mon_redis A /tmp/sess_b86hok0pfj23a81ea3flr0rk03 C /tmp/sess_esmblquiab21m995q2d195j1r5 D /tmp/sess_gl0cmpknk3rirc3l0jmjfd1bo1 C /tmp/sess_ql581nl6ac0uhaj47cftn8ipb7 Afficher le différentiel d'un conteneur :

Slide 16

Slide 16 text

Commandes usuelles $ docker run -d --name=mon_redis redis $ docker stop mon_redis Démarrer en arrière plan avec -d : Arrêter un conteneur :

Slide 17

Slide 17 text

Commandes usuelles $ docker exec mon_redis ls /etc Exécuter une commande dans un conteneur démarré :

Slide 18

Slide 18 text

Commandes usuelles $ docker rmi redis Supprimer une image $ docker rm mon_redis Supprimer un conteneur $ docker stop mon_redis Arrêter un conteneur

Slide 19

Slide 19 text

$ docker Commands: attach Attach to a running container build Build an image from a Dockerfile commit Create a new image from a container's changes cp Copy files/folders from a container's 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 log in to a Docker registry server logout Log out from a Docker registry server logs Fetch the logs of a container port Lookup the public-facing port that is NAT-ed to PRIVATE_PORT pause Pause all processes within a container ps List containers pull Pull an image or a repository from a Docker registry server push Push an image or a repository to a 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 on the Docker Hub 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 unpause Unpause a paused container version Show the Docker version information wait Block until a container stops, then print its exit code

Slide 20

Slide 20 text

Utilisation Dockerfile

Slide 21

Slide 21 text

Dockerfile ● Recette de construction d'un conteneur ● Format de fichier simple FROM ubuntu:14.10 ENV APACHE_LOG_DIR /var/log/apache2 RUN apt-get install -y apache2 ADD site.conf /path/to/site.conf EXPOSE 80 CMD ["/usr/sbin/apache2", "-D", "FOREGROUND"] Exemple non fonctionnel, parce que Apache, c'est pas aussi simple Dans cet exemple, le Dockerfile fait 5 lignes

Slide 22

Slide 22 text

Image Image Dockerfile FROM ubuntu:14.10 [...] [...] [...] Image Image Conteneur Conteneur Conteneur

Slide 23

Slide 23 text

Dockerfile $ vi Dockerfile $ docker run alex/apache $ docker build --name=alex/apache . Step 0 : FROM ubuntu:14.10 ---> 75204fdb260b Step 1 : RUN apt-get install apache2 ---> Running in 68992170d55d Reading package lists... Building dependency tree... Reading state information... Step 2 : ... ---> Running in 68992170d55d ...

Slide 24

Slide 24 text

Dockerfile FROM phusion/baseimage:0.9.13 ENV HOME /root EXPOSE 80 EXPOSE 22 CMD /sbin/my_init RUN apt-get update RUN apt-get install -y \ git curl \ postgresql \ php5-cli php5-fpm php5-intl php5-mcrypt php5-json php5-pgsql php5-curl \ redis-server \ openjdk-7-jre \ nginx # Setup elasticsearch RUN \ cd /tmp && \ curl -o /tmp/elasticsearch-1.3.2.tar.gz https://download.elasticsearch.org/elasticsearch/elasticsearch/elasti csearch-1.3.2.tar.gz && \ tar xvzf elasticsearch-1.3.2.tar.gz && \ rm -f elasticsearch-1.3.2.tar.gz && \ mv /tmp/elasticsearch-1.3.2 /elasticsearch # Setup postgresql RUN /etc/init.d/postgresql start &&\ sudo -u postgres psql --command "CREATE USER gitonomy WITH SUPERUSER PASSWORD 'gitonomy';" &&\ sudo -u postgres createdb -O gitonomy gitonomy RUN echo "host all all 0.0.0.0/0 md5" >> /etc/postgresql/9.3/main/pg_hba.conf RUN echo "listen_addresses='*'" >> /etc/postgresql/9.3/main/postgresql.conf # Node stuff RUN curl -sL https://deb.nodesource.com/setup | bash - RUN apt-get install -y nodejs RUN npm install -g bower grunt-cli # composer RUN curl -o /tmp/composer http://getcomposer.org/composer.phar; mv /tmp/composer /usr/bin/composer; chmod a+x /usr/bin/composer ADD config/nginx.conf /etc/nginx/nginx.conf ADD config/php-fpm.conf /etc/php5/fpm/pool.d/www.conf ADD service/nginx.sh /etc/service/nginx/run ADD service/php-fpm.sh /etc/service/php-fpm/run ADD service/postgresql.sh /etc/service/postgresql/run ADD service/elasticsearch.sh /etc/service/elasticsearch/run ADD service/redis.sh /etc/service/redis/run ADD startup.sh /etc/my_init.d/gitonomy Dans la vraie vie, les Dockerfile font 200 lignes

Slide 25

Slide 25 text

Utilisation Registry

Slide 26

Slide 26 text

Docker Registry Client (vous) Registry PUSH PULL Intégration continue PUSH Sourcecode PUSH Stocker les images pour éviter les constructions

Slide 27

Slide 27 text

Registry $ docker tag alex/apache registry.acme.org/alex/apache $ docker push registry.acme.org/alex/apache

Slide 28

Slide 28 text

Volumes ● Permet de partager des dossiers entre les conteneurs et le système hôte $ docker run \ -v /home/alex/public:/var/www my_apache Le chemin sur mon système Le chemin dans le conteneur

Slide 29

Slide 29 text

Port mapping ● Permet d'exposer des ports du conteneur sur l'hôte $ docker run \ -p 8000:80 my_apache Le port sur mon système Le port dans le conteneur

Slide 30

Slide 30 text

Links $ docker run \ --link mon_redis:mon_redis ubuntu env MON_REDIS_PORT=tcp://172.17.0.2:6379 MON_REDIS_PORT_6379_TCP=tcp://172.17.0.2:6379 MON_REDIS_PORT_6379_TCP_ADDR=172.17.0.2 MON_REDIS_PORT_6379_TCP_PORT=6379 MON_REDIS_PORT_6379_TCP_PROTO=tcp

Slide 31

Slide 31 text

Résumé des fonctionnalités docker run -v /home/alex/public:/var/www -p 8000:80 --link project_db --name project_web my_apache docker run --name=project_db my_mysql

Slide 32

Slide 32 text

Outils

Slide 33

Slide 33 text

fig web: build: . links: - db volumes: - /var/www:/var/www ports: - "8000:8000" db: image: postgres $ fig up web $ docker build --name=web . $ docker run -p 8000:8000 -v /var/www:/var/www --link db web

Slide 34

Slide 34 text

phusion/baseimage ● Framework pour conteneurs Docker ● Multi-process assumé

Slide 35

Slide 35 text

boot2docker ● Pour les utilisateurs Mac ● Bon courage, surtout pour les volumes Macintosh VirtualBox Linux Docker

Slide 36

Slide 36 text

Mais aussi… ● Flynn : automatisation des déploiements ● Shipyard : Docker management ● Mesos & Marathon : Scale ● Gaudi : fig + UI ● Panamax : gestionnaire de conteneurs

Slide 37

Slide 37 text

En conclusion ● Isolez vos projets de votre système ● Versionnez vos Dockerfile ● Automatisez la construction de vos projets