Titre original de cette présentation
donnée à l'occasion du PHP Tour 2014 à Lyon :
Développer et packager votre application Symfony2 avec Docker et Vagrant
* Désormais obsolète voir plutôt
Using Docker with Symfony
(https://symfony.com/doc/current/setup/docker.html)
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
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
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
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
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