Share
Embed
Docker c'est bonheur
Alexandre Salomé
January 15, 2015
Transcript
37 slides
-
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 ? -
Sommaire • Présentation • Utilisation – Dockerfile – Commandes usuelles
– Registry – Volumes – Port mapping – Links • Outils – Fig – Baseimage – Boot2Docker – Flynn -
Avantages • Exécution rapide, isolée et transportable • Mise en
commun des ressources -
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 -
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 -
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 -
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 `-._ `-._`-.__.-'_.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | `-._ `-._`-.__.-'_.-' _.-' `-._ `-.__.-' _.-' `-._ _.-' `-.__.-' -
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 -
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 : -
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 : -
Commandes usuelles $ docker exec mon_redis ls /etc Exécuter une
commande dans un conteneur démarré : -
Commandes usuelles $ docker rmi redis Supprimer une image $
docker rm mon_redis Supprimer un conteneur $ docker stop mon_redis Arrêter un conteneur -
$ 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 -
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 -
Image Image Dockerfile FROM ubuntu:14.10 [...] [...] [...] Image Image
Conteneur Conteneur Conteneur -
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 ... -
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 -
Docker Registry Client (vous) Registry PUSH PULL Intégration continue PUSH
Sourcecode PUSH Stocker les images pour éviter les constructions -
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 -
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 -
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 -
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 -
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 -
boot2docker • Pour les utilisateurs Mac • Bon courage, surtout
pour les volumes Macintosh VirtualBox Linux Docker -
Mais aussi… • Flynn : automatisation des déploiements • Shipyard
: Docker management • Mesos & Marathon : Scale • Gaudi : fig + UI • Panamax : gestionnaire de conteneurs -
En conclusion • Isolez vos projets de votre système •
Versionnez vos Dockerfile • Automatisez la construction de vos projets