SlideShare une entreprise Scribd logo
1  sur  41
Télécharger pour lire hors ligne
Développer et packager votre
application Symfony2 avec
Docker et Vagrant
https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr)
1
Proposition
À partir d'une application Symfony2 ayant fait ses preuves :
- Utilisateurs
- Intégration continue / déploiements automatisés
=> Passer à Docker (sans Puppet / Chef / Ansible ...)
https://github.com/thierrymarianne/symfony2-docker-vagrant
https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr)
2
Projet interne chez DotCloud, Solomon Hykes
Janvier 2014 : Levée de fond de 15M$
9 Juin 2014 : Sortie de la 1.0 à la DockerCon 2014
10 Juin 2014 : Intégration de Docker dans Google App Engine
Un peu d'histoire
https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr)
3
Machines virtuelles !== Containers
https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr)
5
Développement
Intégration continue
Déploiement
Dans quels contextes utiliser Docker ?
https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr)
6
Pour le développeur
Davantage d'indépendance vis à vis des Ops
Meilleure sensation d'être en production sur son poste de travail
https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr)
7
Pour l'opérationnel
Davantage d'indépendance vis à vis des Devs
Faciliter la surcharge des configurations utilisées en développement
(variables d'environnements, fichiers de configuration, persistence)
https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr)
8
En pratique
Container Machine ("machine virtuelle" rapide)
Container Application (rôle au sens gestion de configuration)
Container Volume de Données (point de montage)
https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr)
9
Intégration avec Vagrant
En mode provider
Rôle tenu de manière traditionnel par VirtualBox / VMware
=> Container Machine
$ vagrant init
[...]
config.vm.provider "docker" do |d|
d.image = "afup/nginx"
end
[...]
01.
02.
03.
04.
05.
06.
07.
https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr)
10
"Machine virtuelle" légère ?
Utilisation des images de base Phusion
/sbin/my_init (collecte des processus orphelins)
Runit à la place d'upstart (supervision de service)
Syslog-ng / logrotate
ssh
/! Non-recommandé par Michael Crosby
https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr)
11
Intégration avec Vagrant
• Provisioning
Vagrant.configure("2") do |config|
config.vm.provision "docker",
images: ["afup/symfony2"]
end
• Rôle aussi tenu par Shell / Puppet / Chef
=> Container Application
01.
02.
03.
04.
https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr)
12
Selon le fondateur de Docker
https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr)
13
Ou alors, Boot2Docker!
Linux très léger optimisé pour lancer des containers rapidement
Installation pour OSX / Windows
https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr)
14
Comment utiliser Docker?
Ligne de commande / Dockerfile
https://docs.docker.com/installation/
$ docker -h
Outils de configuration / orchestration
# pip install -U fig
https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr)
15
Application Symfony2 associée à un index
de recherche
16
Le contenu de notre Dockerfile pour notre container Elasticsearch :
$ vi Dockerfile
FROM tutum/elasticsearch
EXPOSE 9200
VOLUME ['/var/lib/elasticsearch']
ENTRYPOINT ["/usr/share/elasticsearch/bin/elasticsearch"]
Ne pas réinventer la roue
01.
02.
03.
04.
05.
06.
https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr)
17
docker build -t afup/elasticsearch:0.1 .
# => nouvelle image créée pour le référentiel
# afup/elasticsearch
# Envoi sur index public
docker push afup/elasticsearch:0.1
# Récupération à partir de l'index public
docker pull afup/elasticsearch:0.1
Contruire une image Elasticsearch
01.
02.
03.
01.
02.
01.
02.
https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr)
18
docker run -d -p :9200 
--name elasticsearch-server 
-v `pwd`/elasticsearch:/var/lib/elasticsearch 
afup/elasticsearch:0.1
Démarrer notre container à partir de l'image
01.
02.
03.
04.
https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr)
19
docker run -d -p :9200 
--name elasticsearch-server 
--volumes-from elasticsearch-data-volume 
-v `pwd`/elasticsearch:/var/lib/elasticsearch 
afup/elasticsearch:0.1
Tagger notre container Elasticsearch
01.
02.
03.
04.
05.
https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr)
20
docker run -d -p :9200 
--name elasticsearch-server 
--volumes-from elasticsearch-data-volume 
-v `pwd`/elasticsearch:/var/lib/elasticsearch 
afup/elasticsearch:0.1
Déclarer un Container Volume de Données
01.
02.
03.
04.
05.
https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr)
21
Avec montage de notre application Symfony2
docker run -t -i -p 80:80 
--name php-nginx-server 
--link elasticsearch-server:symfony__elasticsearch_ 
-v symfony2:/var/www/symfony2 
-v `pwd`/nginx/sites-enabled:/etc/nginx/sites-enabled 
# [...]
afup/nginx:0.1
Lancer un Container Application (nginx)
01.
02.
03.
04.
05.
06.
07.
https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr)
22
docker run -t -i -p 80:80 
--name php-nginx-server 
--link elasticsearch-server:symfony__elasticsearch_ 
-v symfony2:/var/www/symfony2 
-v `pwd`/nginx/sites-enabled:/etc/nginx/sites-enabled 
afup/nginx:0.1
Lier nos containers Elasticsearch et nginx
01.
02.
03.
04.
05.
06.
https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr)
23
# Définition de paramètres de configuration en yaml
parameters:
elasticsearch_host: %elasticsearch.host%
elasticsearch_port: %elasticsearch.port%
gmail_search_index: gmail
twitter_search_index: twitter
Configuration de notre application
01.
02.
03.
04.
05.
06.
https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr)
24
docker run -t -i -p 80:80 
--name php-nginx-server 
--e SYMFONY__ELASTICSEARCH__HOST=127.0.0.1
-v symfony2:/var/www/symfony2 
-v `pwd`/nginx/sites-enabled:/etc/nginx/sites-enabled 
afup/nginx:0.1
root@ad09c8a66671:# dans mon container Elasticsearch
root@ad09c8a66671:env
root@ad09c8a66671:SYMFONY__ELASTICSEARCH__HOST=127.0.0.1
Variables d'environnement (1/2)
Injection d'une variable au démarrage d'un container
01.
02.
03.
04.
05.
06.
01.
02.
03.
25
docker run -t -i -p 80:80 
--name php-nginx-server 
--link elasticsearch-server:symfony__elasticsearch_ 
-v symfony2:/var/www/symfony2 
-v `pwd`/nginx/sites-enabled:/etc/nginx/sites-enabled 
afup/nginx:0.1
SYMFONY__ELASTICSEARCH__HOST <=> %elasticsearch.host%
Lier deux containers transfère les variables d'environnement
Variables d'environnement (2/2)
01.
02.
03.
04.
05.
06.
https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr)
26
FROM ubuntu:14.04
ENV DEBIAN_FRONTEND noninteractive
# RUN apt-get upgrade à bannir
RUN apt-get update
RUN apt-get install -y --force-yes software-properties-common
Pro Tip: Abuser des images officielles
01.
02.
03.
04.
05.
06.
07.
https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr)
27
sudo apt-get install squid-deb-proxy avahi-utils
https://github.com/yasn77/docker-squid-repo-cache.git
Pro Tip: Proxy Packages Debian (1/2)
Proxy pour gestionnaire de paquets sur la machine hôte
Peut être même dans son propre container ?
01.
02.
03.
01.
02.
03.
https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr)
28
RUN route -n | awk '/^0.0.0.0/ {print $2}' > /tmp/host_ip.txt
RUN echo "HEAD /" | nc `cat /tmp/host_ip.txt` 8000 | 
grep squid-deb-proxy 
&& (echo "Acquire::http::Proxy "http://$(cat /tmp/host_ip.txt):8000"
/etc/apt/apt.conf.d/30proxy) 
&& (echo "Acquire::http::Proxy::ppa.launchpad.net DIRECT;" >> 
/etc/apt/apt.conf.d/30proxy) 
|| echo "No squid-deb-proxy detected on docker host"
Pro Tip: Proxy Packages Debian (2/2)
Dans mon Dockerfile, avant l'installation de paquets :
01.
02.
03.
04.
05.
06.
07.
08.
https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr)
29
RUN apt-get install -y --force-yes nginx
RUN apt-get install -y --force-yes php5-fpm
Différent de
RUN apt-get install -y --force-yes php5-fpm
RUN apt-get install -y --force-yes nginx
Pro Tip: Tirer parti du cache de Docker
Dans vos Dockerfiles :
Conserver au maximum l'ordre des instructions!
01.
02.
01.
02.
https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr)
30
Pro Tip: Proxy Toran pour composer
Par l'un des lead développeurs de Composer (Jordi Boggiano)
Accélérer l'installation des vendors
Sert de point de redondance avec github / référentiels privés
=> Container Application
https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr)
31
# fig.yml
nginx:
build: /home/afup/php-nginx
links:
- elasticsearch:symfony__elasticsearch_ [...]
ports:
- "8081:80"
expose:
- "80"
Et si on se débarrassait (en partie) du shell ?
01.
02.
03.
04.
05.
06.
07.
08.
09.
10.
https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr)
32
elasticsearch:
image: afup/elasticsearch:0.1
volumes_from: elasticsearch-data-volume
expose:
- "9200"
ports:
- ":9200"
Fig
Où se cache notre application Symfony2 cette fois ?
01.
02.
03.
04.
05.
06.
07.
https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr)
33
nginx:
[...]
volumes:
- nginx/sites-enabled:/etc/nginx/sites-enabled
- symfony2:/var/www/symfony2
$ fig up
Fig
01.
02.
03.
04.
05.
06.
07.
https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr)
34
La vie des containers avec Cadvisor
https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr)
35
Aller encore plus loin avec OpenStack
Avec OpenStack (cloud manager)
https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr)
36
description: >
Stack Heat (Orchestration)
resources:
nginx:
type: DockerInc::Docker::Container
properties:
image: afup/php-nginx:0.1
elasticsearch:
type: DockerInc::Docker::Container
[...]
Démarrer une "Stack" avec Heat
heat stack-create nginx -f ../openstack/php-nginx.yml
01.
02.
03.
04.
05.
06.
07.
08.
09.
10.
https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr)
37
Et ce n'est que le début !
Orchestration avec Maestro-Ng
Configuration visuelle avec Gaudi
Déploiement avec Deis / CoreOS
Support de Docker avec AppEngine
https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr)
38
Showtime
• /! Effet démo en perspective !!
https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr)
39
Questions ?
https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr)
40
Sources
• https://linuxcontainers.org
• http://en.wikipedia.org/wiki/Chroot
• http://en.wikipedia.org/wiki/Cgroups
• https://www.docker.io
• https://hub.docker.com/
• https://speakerdeck.com/ubermuda/a-multi-container-symfony2-setup-with-docker
• https://wiki.openstack.org/wiki/Solum
• https://speakerdeck.com/ubermuda/a-multi-container-symfony2-setup-with-docker
• http://blog.docker.com/2014/04/openstack-update-icehouse-release-update/
• https://github.com/phusion/baseimage-docker
• http://crosbymichael.com/dockerfile-best-practices.html
• https://toranproxy.com/
• http://openstack.redhat.com/Quickstart/
https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr)
41

Contenu connexe

Tendances

Julien Maitrehenry - Docker, ça mange quoi au printemps
Julien Maitrehenry - Docker, ça mange quoi au printempsJulien Maitrehenry - Docker, ça mange quoi au printemps
Julien Maitrehenry - Docker, ça mange quoi au printempsWeb à Québec
 
Kubernetes Meetup Paris #5 - Metriques applicatives k8s
Kubernetes Meetup Paris #5 - Metriques applicatives k8sKubernetes Meetup Paris #5 - Metriques applicatives k8s
Kubernetes Meetup Paris #5 - Metriques applicatives k8sArnaud MAZIN
 
Workshop mesos docker devoxx fr 2016
Workshop mesos docker devoxx fr 2016Workshop mesos docker devoxx fr 2016
Workshop mesos docker devoxx fr 2016Julia Mateo
 
Docker Tours Meetup #1 - Introduction à Docker
Docker Tours Meetup #1 - Introduction à DockerDocker Tours Meetup #1 - Introduction à Docker
Docker Tours Meetup #1 - Introduction à DockerThibaut Marmin
 
Introduction à Docker et Gaudi
Introduction à Docker et GaudiIntroduction à Docker et Gaudi
Introduction à Docker et GaudiEmmanuel Quentin
 
Présentation CoreOS
Présentation CoreOSPrésentation CoreOS
Présentation CoreOSgcatt
 
Docker du mythe à la réalité
Docker du mythe à la réalitéDocker du mythe à la réalité
Docker du mythe à la réalitéZenika
 
Introduction à docker.io
Introduction à docker.ioIntroduction à docker.io
Introduction à docker.ioNicolas Hennion
 
Retour d'expérience Docker: Puissance et simplicité de VSTS, déploiement sur ...
Retour d'expérience Docker: Puissance et simplicité de VSTS, déploiement sur ...Retour d'expérience Docker: Puissance et simplicité de VSTS, déploiement sur ...
Retour d'expérience Docker: Puissance et simplicité de VSTS, déploiement sur ...Cédric Leblond
 
Alter Way's digitalks - Docker : des conteneurs pour tout faire ?
Alter Way's digitalks - Docker  : des conteneurs pour tout faire ?Alter Way's digitalks - Docker  : des conteneurs pour tout faire ?
Alter Way's digitalks - Docker : des conteneurs pour tout faire ?ALTER WAY
 
Docker nice meetup #1 construire, déployer et exécuter vos applications, ...
Docker nice meetup #1   construire, déployer et exécuter vos applications, ...Docker nice meetup #1   construire, déployer et exécuter vos applications, ...
Docker nice meetup #1 construire, déployer et exécuter vos applications, ...adri1s
 
Déploiements avec Docker
Déploiements avec DockerDéploiements avec Docker
Déploiements avec DockerLuis Lopez
 
Docker ! De la découverte à la mise en production / Digital apéro [19/03/2015]
Docker ! De la découverte à la mise en production / Digital apéro [19/03/2015]Docker ! De la découverte à la mise en production / Digital apéro [19/03/2015]
Docker ! De la découverte à la mise en production / Digital apéro [19/03/2015]Silicon Comté
 
CI, CD, pipelines, conteneurs : la cohabitation est elle possible ?
CI, CD, pipelines, conteneurs : la cohabitation est elle possible ?CI, CD, pipelines, conteneurs : la cohabitation est elle possible ?
CI, CD, pipelines, conteneurs : la cohabitation est elle possible ?Membré Guillaume
 
Oxalide Workshop #4 - Docker, des tours dans le petit bassin
Oxalide Workshop #4 - Docker, des tours dans le petit bassinOxalide Workshop #4 - Docker, des tours dans le petit bassin
Oxalide Workshop #4 - Docker, des tours dans le petit bassinLudovic Piot
 
Retour d'expérience technique Go, gRPC, Kubernetes
Retour d'expérience technique Go, gRPC, KubernetesRetour d'expérience technique Go, gRPC, Kubernetes
Retour d'expérience technique Go, gRPC, KubernetesVincent Composieux
 
Midi technique - présentation docker
Midi technique - présentation dockerMidi technique - présentation docker
Midi technique - présentation dockerOlivier Eeckhoutte
 

Tendances (20)

Docker - YaJUG
Docker  - YaJUGDocker  - YaJUG
Docker - YaJUG
 
Julien Maitrehenry - Docker, ça mange quoi au printemps
Julien Maitrehenry - Docker, ça mange quoi au printempsJulien Maitrehenry - Docker, ça mange quoi au printemps
Julien Maitrehenry - Docker, ça mange quoi au printemps
 
Kubernetes Meetup Paris #5 - Metriques applicatives k8s
Kubernetes Meetup Paris #5 - Metriques applicatives k8sKubernetes Meetup Paris #5 - Metriques applicatives k8s
Kubernetes Meetup Paris #5 - Metriques applicatives k8s
 
Workshop mesos docker devoxx fr 2016
Workshop mesos docker devoxx fr 2016Workshop mesos docker devoxx fr 2016
Workshop mesos docker devoxx fr 2016
 
Docker Tours Meetup #1 - Introduction à Docker
Docker Tours Meetup #1 - Introduction à DockerDocker Tours Meetup #1 - Introduction à Docker
Docker Tours Meetup #1 - Introduction à Docker
 
Introduction à Docker et Gaudi
Introduction à Docker et GaudiIntroduction à Docker et Gaudi
Introduction à Docker et Gaudi
 
Présentation CoreOS
Présentation CoreOSPrésentation CoreOS
Présentation CoreOS
 
Docker du mythe à la réalité
Docker du mythe à la réalitéDocker du mythe à la réalité
Docker du mythe à la réalité
 
Introduction à docker.io
Introduction à docker.ioIntroduction à docker.io
Introduction à docker.io
 
Retour d'expérience Docker: Puissance et simplicité de VSTS, déploiement sur ...
Retour d'expérience Docker: Puissance et simplicité de VSTS, déploiement sur ...Retour d'expérience Docker: Puissance et simplicité de VSTS, déploiement sur ...
Retour d'expérience Docker: Puissance et simplicité de VSTS, déploiement sur ...
 
Alter Way's digitalks - Docker : des conteneurs pour tout faire ?
Alter Way's digitalks - Docker  : des conteneurs pour tout faire ?Alter Way's digitalks - Docker  : des conteneurs pour tout faire ?
Alter Way's digitalks - Docker : des conteneurs pour tout faire ?
 
Docker nice meetup #1 construire, déployer et exécuter vos applications, ...
Docker nice meetup #1   construire, déployer et exécuter vos applications, ...Docker nice meetup #1   construire, déployer et exécuter vos applications, ...
Docker nice meetup #1 construire, déployer et exécuter vos applications, ...
 
Déploiements avec Docker
Déploiements avec DockerDéploiements avec Docker
Déploiements avec Docker
 
Docker ! De la découverte à la mise en production / Digital apéro [19/03/2015]
Docker ! De la découverte à la mise en production / Digital apéro [19/03/2015]Docker ! De la découverte à la mise en production / Digital apéro [19/03/2015]
Docker ! De la découverte à la mise en production / Digital apéro [19/03/2015]
 
Livre blanc docker
Livre blanc docker Livre blanc docker
Livre blanc docker
 
CI, CD, pipelines, conteneurs : la cohabitation est elle possible ?
CI, CD, pipelines, conteneurs : la cohabitation est elle possible ?CI, CD, pipelines, conteneurs : la cohabitation est elle possible ?
CI, CD, pipelines, conteneurs : la cohabitation est elle possible ?
 
Oxalide Workshop #4 - Docker, des tours dans le petit bassin
Oxalide Workshop #4 - Docker, des tours dans le petit bassinOxalide Workshop #4 - Docker, des tours dans le petit bassin
Oxalide Workshop #4 - Docker, des tours dans le petit bassin
 
Retour d'expérience technique Go, gRPC, Kubernetes
Retour d'expérience technique Go, gRPC, KubernetesRetour d'expérience technique Go, gRPC, Kubernetes
Retour d'expérience technique Go, gRPC, Kubernetes
 
Présentation Docker
Présentation DockerPrésentation Docker
Présentation Docker
 
Midi technique - présentation docker
Midi technique - présentation dockerMidi technique - présentation docker
Midi technique - présentation docker
 

Similaire à Distribuer une application avec Symfony & Docker *

5390997 Support formation : Construire et administrer vos conteneurs avec Doc...
5390997 Support formation : Construire et administrer vos conteneurs avec Doc...5390997 Support formation : Construire et administrer vos conteneurs avec Doc...
5390997 Support formation : Construire et administrer vos conteneurs avec Doc...AbdellahELMAMOUN
 
De la chaîne de production au SI géré par des logiciels
De la chaîne de production au SI géré par des logicielsDe la chaîne de production au SI géré par des logiciels
De la chaîne de production au SI géré par des logicielsJohan Moreau
 
Oxalide Workshop #4 - Docker, des tours dans le petit bassin
Oxalide Workshop #4 - Docker, des tours dans le petit bassinOxalide Workshop #4 - Docker, des tours dans le petit bassin
Oxalide Workshop #4 - Docker, des tours dans le petit bassinOxalide
 
Docker le buzz est il justifié ?
Docker le buzz est il justifié ? Docker le buzz est il justifié ?
Docker le buzz est il justifié ? Romain Chalumeau
 
Spring Boot & Containers - Do's & Don'ts
Spring Boot & Containers - Do's & Don'tsSpring Boot & Containers - Do's & Don'ts
Spring Boot & Containers - Do's & Don'tsJulien Wittouck
 
Pyconfr2018 deploy des application python dans un cluster open shift
Pyconfr2018 deploy des application python dans un cluster open shiftPyconfr2018 deploy des application python dans un cluster open shift
Pyconfr2018 deploy des application python dans un cluster open shiftArthur Lutz
 
Capitole du Libre 2018 - Déployer des applications python dans un cluster Ope...
Capitole du Libre 2018 - Déployer des applications python dans un cluster Ope...Capitole du Libre 2018 - Déployer des applications python dans un cluster Ope...
Capitole du Libre 2018 - Déployer des applications python dans un cluster Ope...Arthur Lutz
 
Docker, mais qu’est-ce que c’est ?
Docker, mais qu’est-ce que c’est ?Docker, mais qu’est-ce que c’est ?
Docker, mais qu’est-ce que c’est ?Julien Maitrehenry
 
Support : introduction à docker
Support : introduction à dockerSupport : introduction à docker
Support : introduction à dockerBoubker ABERWAG
 
Docker, ça mange quoi au printemps
Docker, ça mange quoi au printempsDocker, ça mange quoi au printemps
Docker, ça mange quoi au printempsJulien Maitrehenry
 
Alphorm.com Formation Odoo Technique : Installer et Configurer
Alphorm.com Formation Odoo Technique : Installer et ConfigurerAlphorm.com Formation Odoo Technique : Installer et Configurer
Alphorm.com Formation Odoo Technique : Installer et ConfigurerAlphorm
 
Terraform OpenStack : Mise en pratique sur infrastructure OVH (Rennes devops)
Terraform OpenStack : Mise en pratique sur infrastructure OVH (Rennes devops) Terraform OpenStack : Mise en pratique sur infrastructure OVH (Rennes devops)
Terraform OpenStack : Mise en pratique sur infrastructure OVH (Rennes devops) Joël Séguillon
 
20111220 lyon jug-packaging-natif
20111220 lyon jug-packaging-natif20111220 lyon jug-packaging-natif
20111220 lyon jug-packaging-natifHenri Gomez
 
Gitlab CI : Integration et Déploiement Continue
Gitlab CI : Integration et Déploiement ContinueGitlab CI : Integration et Déploiement Continue
Gitlab CI : Integration et Déploiement ContinueVincent Composieux
 
2023-02-02 - Marvelous March
2023-02-02 - Marvelous March2023-02-02 - Marvelous March
2023-02-02 - Marvelous MarchFrederic Leger
 
Ce qu'il faut retenir de la FrenchKit iOS
Ce qu'il faut retenir de la FrenchKit iOSCe qu'il faut retenir de la FrenchKit iOS
Ce qu'il faut retenir de la FrenchKit iOSNiji
 
20120110 paris jug-packaging-natif
20120110 paris jug-packaging-natif20120110 paris jug-packaging-natif
20120110 paris jug-packaging-natifHenri Gomez
 
A la découverte de docker
A la découverte de dockerA la découverte de docker
A la découverte de dockerjean pasqualini
 

Similaire à Distribuer une application avec Symfony & Docker * (20)

5390997 Support formation : Construire et administrer vos conteneurs avec Doc...
5390997 Support formation : Construire et administrer vos conteneurs avec Doc...5390997 Support formation : Construire et administrer vos conteneurs avec Doc...
5390997 Support formation : Construire et administrer vos conteneurs avec Doc...
 
De la chaîne de production au SI géré par des logiciels
De la chaîne de production au SI géré par des logicielsDe la chaîne de production au SI géré par des logiciels
De la chaîne de production au SI géré par des logiciels
 
Oxalide Workshop #4 - Docker, des tours dans le petit bassin
Oxalide Workshop #4 - Docker, des tours dans le petit bassinOxalide Workshop #4 - Docker, des tours dans le petit bassin
Oxalide Workshop #4 - Docker, des tours dans le petit bassin
 
Docker le buzz est il justifié ?
Docker le buzz est il justifié ? Docker le buzz est il justifié ?
Docker le buzz est il justifié ?
 
Spring Boot & Containers - Do's & Don'ts
Spring Boot & Containers - Do's & Don'tsSpring Boot & Containers - Do's & Don'ts
Spring Boot & Containers - Do's & Don'ts
 
Pyconfr2018 deploy des application python dans un cluster open shift
Pyconfr2018 deploy des application python dans un cluster open shiftPyconfr2018 deploy des application python dans un cluster open shift
Pyconfr2018 deploy des application python dans un cluster open shift
 
Capitole du Libre 2018 - Déployer des applications python dans un cluster Ope...
Capitole du Libre 2018 - Déployer des applications python dans un cluster Ope...Capitole du Libre 2018 - Déployer des applications python dans un cluster Ope...
Capitole du Libre 2018 - Déployer des applications python dans un cluster Ope...
 
Docker, mais qu’est-ce que c’est ?
Docker, mais qu’est-ce que c’est ?Docker, mais qu’est-ce que c’est ?
Docker, mais qu’est-ce que c’est ?
 
Support : introduction à docker
Support : introduction à dockerSupport : introduction à docker
Support : introduction à docker
 
Docker, ça mange quoi au printemps
Docker, ça mange quoi au printempsDocker, ça mange quoi au printemps
Docker, ça mange quoi au printemps
 
Alphorm.com Formation Odoo Technique : Installer et Configurer
Alphorm.com Formation Odoo Technique : Installer et ConfigurerAlphorm.com Formation Odoo Technique : Installer et Configurer
Alphorm.com Formation Odoo Technique : Installer et Configurer
 
Terraform OpenStack : Mise en pratique sur infrastructure OVH (Rennes devops)
Terraform OpenStack : Mise en pratique sur infrastructure OVH (Rennes devops) Terraform OpenStack : Mise en pratique sur infrastructure OVH (Rennes devops)
Terraform OpenStack : Mise en pratique sur infrastructure OVH (Rennes devops)
 
20111220 lyon jug-packaging-natif
20111220 lyon jug-packaging-natif20111220 lyon jug-packaging-natif
20111220 lyon jug-packaging-natif
 
Gitlab CI : Integration et Déploiement Continue
Gitlab CI : Integration et Déploiement ContinueGitlab CI : Integration et Déploiement Continue
Gitlab CI : Integration et Déploiement Continue
 
Vagrant - Concept
Vagrant - ConceptVagrant - Concept
Vagrant - Concept
 
2023-02-02 - Marvelous March
2023-02-02 - Marvelous March2023-02-02 - Marvelous March
2023-02-02 - Marvelous March
 
Ce qu'il faut retenir de la FrenchKit iOS
Ce qu'il faut retenir de la FrenchKit iOSCe qu'il faut retenir de la FrenchKit iOS
Ce qu'il faut retenir de la FrenchKit iOS
 
20120110 paris jug-packaging-natif
20120110 paris jug-packaging-natif20120110 paris jug-packaging-natif
20120110 paris jug-packaging-natif
 
A la découverte de docker
A la découverte de dockerA la découverte de docker
A la découverte de docker
 
Tp docker-v21
Tp docker-v21Tp docker-v21
Tp docker-v21
 

Distribuer une application avec Symfony & Docker *

  • 1. Développer et packager votre application Symfony2 avec Docker et Vagrant https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr) 1
  • 2. Proposition À partir d'une application Symfony2 ayant fait ses preuves : - Utilisateurs - Intégration continue / déploiements automatisés => Passer à Docker (sans Puppet / Chef / Ansible ...) https://github.com/thierrymarianne/symfony2-docker-vagrant https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr) 2
  • 3. Projet interne chez DotCloud, Solomon Hykes Janvier 2014 : Levée de fond de 15M$ 9 Juin 2014 : Sortie de la 1.0 à la DockerCon 2014 10 Juin 2014 : Intégration de Docker dans Google App Engine Un peu d'histoire https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr) 3
  • 4.
  • 5. Machines virtuelles !== Containers https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr) 5
  • 6. Développement Intégration continue Déploiement Dans quels contextes utiliser Docker ? https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr) 6
  • 7. Pour le développeur Davantage d'indépendance vis à vis des Ops Meilleure sensation d'être en production sur son poste de travail https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr) 7
  • 8. Pour l'opérationnel Davantage d'indépendance vis à vis des Devs Faciliter la surcharge des configurations utilisées en développement (variables d'environnements, fichiers de configuration, persistence) https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr) 8
  • 9. En pratique Container Machine ("machine virtuelle" rapide) Container Application (rôle au sens gestion de configuration) Container Volume de Données (point de montage) https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr) 9
  • 10. Intégration avec Vagrant En mode provider Rôle tenu de manière traditionnel par VirtualBox / VMware => Container Machine $ vagrant init [...] config.vm.provider "docker" do |d| d.image = "afup/nginx" end [...] 01. 02. 03. 04. 05. 06. 07. https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr) 10
  • 11. "Machine virtuelle" légère ? Utilisation des images de base Phusion /sbin/my_init (collecte des processus orphelins) Runit à la place d'upstart (supervision de service) Syslog-ng / logrotate ssh /! Non-recommandé par Michael Crosby https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr) 11
  • 12. Intégration avec Vagrant • Provisioning Vagrant.configure("2") do |config| config.vm.provision "docker", images: ["afup/symfony2"] end • Rôle aussi tenu par Shell / Puppet / Chef => Container Application 01. 02. 03. 04. https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr) 12
  • 13. Selon le fondateur de Docker https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr) 13
  • 14. Ou alors, Boot2Docker! Linux très léger optimisé pour lancer des containers rapidement Installation pour OSX / Windows https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr) 14
  • 15. Comment utiliser Docker? Ligne de commande / Dockerfile https://docs.docker.com/installation/ $ docker -h Outils de configuration / orchestration # pip install -U fig https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr) 15
  • 16. Application Symfony2 associée à un index de recherche 16
  • 17. Le contenu de notre Dockerfile pour notre container Elasticsearch : $ vi Dockerfile FROM tutum/elasticsearch EXPOSE 9200 VOLUME ['/var/lib/elasticsearch'] ENTRYPOINT ["/usr/share/elasticsearch/bin/elasticsearch"] Ne pas réinventer la roue 01. 02. 03. 04. 05. 06. https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr) 17
  • 18. docker build -t afup/elasticsearch:0.1 . # => nouvelle image créée pour le référentiel # afup/elasticsearch # Envoi sur index public docker push afup/elasticsearch:0.1 # Récupération à partir de l'index public docker pull afup/elasticsearch:0.1 Contruire une image Elasticsearch 01. 02. 03. 01. 02. 01. 02. https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr) 18
  • 19. docker run -d -p :9200 --name elasticsearch-server -v `pwd`/elasticsearch:/var/lib/elasticsearch afup/elasticsearch:0.1 Démarrer notre container à partir de l'image 01. 02. 03. 04. https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr) 19
  • 20. docker run -d -p :9200 --name elasticsearch-server --volumes-from elasticsearch-data-volume -v `pwd`/elasticsearch:/var/lib/elasticsearch afup/elasticsearch:0.1 Tagger notre container Elasticsearch 01. 02. 03. 04. 05. https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr) 20
  • 21. docker run -d -p :9200 --name elasticsearch-server --volumes-from elasticsearch-data-volume -v `pwd`/elasticsearch:/var/lib/elasticsearch afup/elasticsearch:0.1 Déclarer un Container Volume de Données 01. 02. 03. 04. 05. https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr) 21
  • 22. Avec montage de notre application Symfony2 docker run -t -i -p 80:80 --name php-nginx-server --link elasticsearch-server:symfony__elasticsearch_ -v symfony2:/var/www/symfony2 -v `pwd`/nginx/sites-enabled:/etc/nginx/sites-enabled # [...] afup/nginx:0.1 Lancer un Container Application (nginx) 01. 02. 03. 04. 05. 06. 07. https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr) 22
  • 23. docker run -t -i -p 80:80 --name php-nginx-server --link elasticsearch-server:symfony__elasticsearch_ -v symfony2:/var/www/symfony2 -v `pwd`/nginx/sites-enabled:/etc/nginx/sites-enabled afup/nginx:0.1 Lier nos containers Elasticsearch et nginx 01. 02. 03. 04. 05. 06. https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr) 23
  • 24. # Définition de paramètres de configuration en yaml parameters: elasticsearch_host: %elasticsearch.host% elasticsearch_port: %elasticsearch.port% gmail_search_index: gmail twitter_search_index: twitter Configuration de notre application 01. 02. 03. 04. 05. 06. https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr) 24
  • 25. docker run -t -i -p 80:80 --name php-nginx-server --e SYMFONY__ELASTICSEARCH__HOST=127.0.0.1 -v symfony2:/var/www/symfony2 -v `pwd`/nginx/sites-enabled:/etc/nginx/sites-enabled afup/nginx:0.1 root@ad09c8a66671:# dans mon container Elasticsearch root@ad09c8a66671:env root@ad09c8a66671:SYMFONY__ELASTICSEARCH__HOST=127.0.0.1 Variables d'environnement (1/2) Injection d'une variable au démarrage d'un container 01. 02. 03. 04. 05. 06. 01. 02. 03. 25
  • 26. docker run -t -i -p 80:80 --name php-nginx-server --link elasticsearch-server:symfony__elasticsearch_ -v symfony2:/var/www/symfony2 -v `pwd`/nginx/sites-enabled:/etc/nginx/sites-enabled afup/nginx:0.1 SYMFONY__ELASTICSEARCH__HOST <=> %elasticsearch.host% Lier deux containers transfère les variables d'environnement Variables d'environnement (2/2) 01. 02. 03. 04. 05. 06. https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr) 26
  • 27. FROM ubuntu:14.04 ENV DEBIAN_FRONTEND noninteractive # RUN apt-get upgrade à bannir RUN apt-get update RUN apt-get install -y --force-yes software-properties-common Pro Tip: Abuser des images officielles 01. 02. 03. 04. 05. 06. 07. https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr) 27
  • 28. sudo apt-get install squid-deb-proxy avahi-utils https://github.com/yasn77/docker-squid-repo-cache.git Pro Tip: Proxy Packages Debian (1/2) Proxy pour gestionnaire de paquets sur la machine hôte Peut être même dans son propre container ? 01. 02. 03. 01. 02. 03. https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr) 28
  • 29. RUN route -n | awk '/^0.0.0.0/ {print $2}' > /tmp/host_ip.txt RUN echo "HEAD /" | nc `cat /tmp/host_ip.txt` 8000 | grep squid-deb-proxy && (echo "Acquire::http::Proxy "http://$(cat /tmp/host_ip.txt):8000" /etc/apt/apt.conf.d/30proxy) && (echo "Acquire::http::Proxy::ppa.launchpad.net DIRECT;" >> /etc/apt/apt.conf.d/30proxy) || echo "No squid-deb-proxy detected on docker host" Pro Tip: Proxy Packages Debian (2/2) Dans mon Dockerfile, avant l'installation de paquets : 01. 02. 03. 04. 05. 06. 07. 08. https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr) 29
  • 30. RUN apt-get install -y --force-yes nginx RUN apt-get install -y --force-yes php5-fpm Différent de RUN apt-get install -y --force-yes php5-fpm RUN apt-get install -y --force-yes nginx Pro Tip: Tirer parti du cache de Docker Dans vos Dockerfiles : Conserver au maximum l'ordre des instructions! 01. 02. 01. 02. https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr) 30
  • 31. Pro Tip: Proxy Toran pour composer Par l'un des lead développeurs de Composer (Jordi Boggiano) Accélérer l'installation des vendors Sert de point de redondance avec github / référentiels privés => Container Application https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr) 31
  • 32. # fig.yml nginx: build: /home/afup/php-nginx links: - elasticsearch:symfony__elasticsearch_ [...] ports: - "8081:80" expose: - "80" Et si on se débarrassait (en partie) du shell ? 01. 02. 03. 04. 05. 06. 07. 08. 09. 10. https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr) 32
  • 33. elasticsearch: image: afup/elasticsearch:0.1 volumes_from: elasticsearch-data-volume expose: - "9200" ports: - ":9200" Fig Où se cache notre application Symfony2 cette fois ? 01. 02. 03. 04. 05. 06. 07. https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr) 33
  • 34. nginx: [...] volumes: - nginx/sites-enabled:/etc/nginx/sites-enabled - symfony2:/var/www/symfony2 $ fig up Fig 01. 02. 03. 04. 05. 06. 07. https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr) 34
  • 35. La vie des containers avec Cadvisor https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr) 35
  • 36. Aller encore plus loin avec OpenStack Avec OpenStack (cloud manager) https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr) 36
  • 37. description: > Stack Heat (Orchestration) resources: nginx: type: DockerInc::Docker::Container properties: image: afup/php-nginx:0.1 elasticsearch: type: DockerInc::Docker::Container [...] Démarrer une "Stack" avec Heat heat stack-create nginx -f ../openstack/php-nginx.yml 01. 02. 03. 04. 05. 06. 07. 08. 09. 10. https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr) 37
  • 38. Et ce n'est que le début ! Orchestration avec Maestro-Ng Configuration visuelle avec Gaudi Déploiement avec Deis / CoreOS Support de Docker avec AppEngine https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr) 38
  • 39. Showtime • /! Effet démo en perspective !! https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr) 39
  • 41. Sources • https://linuxcontainers.org • http://en.wikipedia.org/wiki/Chroot • http://en.wikipedia.org/wiki/Cgroups • https://www.docker.io • https://hub.docker.com/ • https://speakerdeck.com/ubermuda/a-multi-container-symfony2-setup-with-docker • https://wiki.openstack.org/wiki/Solum • https://speakerdeck.com/ubermuda/a-multi-container-symfony2-setup-with-docker • http://blog.docker.com/2014/04/openstack-update-icehouse-release-update/ • https://github.com/phusion/baseimage-docker • http://crosbymichael.com/dockerfile-best-practices.html • https://toranproxy.com/ • http://openstack.redhat.com/Quickstart/ https://joind.in/11240 (@thierrymarianne | thierrym@theodo[point]fr) 41