dans le développement
et l'intégration continue
@jderusse
SensioLabs
Virtualisation
Projet A
- zend server
- mysql
- php 5.3
Projet B
- 5 × apache2
- 5 × postgresql
- php 5.4
- rabbitmq
Projet C
- apache2
- mysql
- php 5.6
- oracle
- solr
- ldap
Solution : VM ?
VM
Container
Concrètement
VirtualBox
docker
Démarrage
~ 1 min
~ 0.3 sec
Mémoire
~ 256 Mo
~ 1 Mo
Espace disque
~ 1 Go
~ 100 Ko
Et pour
Windows et OS X ?
-
boot2docker
-
docker-machine
-
Kitematic
$ docker-compose up -d
Creating project_db_1...
Creating project_web_1...
$ docker-compose scale web=3
Starting project_web_2...
Starting project_web_3...
$ docker-compose ps
Name Command State Ports
-------------- -----------------------------------
project_web_1 apache2-foreground Up 80/tcp
project_web_2 apache2-foreground Up 80/tcp
project_web_3 apache2-foreground Up 80/tcp
project_db_1 mysqld Up 3306/tcp
$ docker-compose logs web
Attaching to project_web_3, project_web_2, project_web_1
app_2 | RUN apache
app_1 | RUN apache
app_3 | RUN apache
docker-compose
# docker-compose.yml
web:
image: php:5.6-apache
links:
- db:db
volumes:
- .:/var/www/html
db:
image: postgres
anciennement fig
Accéder aux containers
Accéder aux containers
Ports
# docker-compose.yml
web:
image: php:5.6-apache
ports:
- "8080:80"
links:
- db:db
volumes:
- .:/var/www/html
db:
image: postgres
ports:
- "3306:3306"
E_TOO_MANY_PORTS
# A/docker-compose.yml
web:
image: php:5.6-apache
ports:
- "8080:80"
links:
- db:db
volumes:
- .:/var/www/html
db:
image: postgres
ports:
- "3306:3306"
# B/docker-compose.yml
web:
image: php:5.6-apache
ports:
- "8081:80"
links:
- db:db
volumes:
- .:/var/www/html
db:
image: postgres
ports:
- "3307:3306"
# C/docker-compose.yml
web:
image: php:5.6-apache
ports:
- "8084:80"
links:
- db:db
volumes:
- .:/var/www/html
db:
image: postgres
ports:
- "3308:3306"
docker-gen + Dnsmasq
# docker-compose.yml
web:
image: php:5.6-apache
environment:
- DOMAIN_NAME=web.project.docker
links:
- db:db
volumes:
- .:/var/www/html
$ nslookup web.project.docker
Server: 172.17.42.1
Address: 172.17.42.1#53
Name: web.project.docker
Address: 172.17.0.193
Launch time?
Solution ?
// app_dev.php
// This check prevents access to debug front controllers that are deploy
// Feel free to remove this, extend it, or make something more sophistic
if (isset($_SERVER['HTTP_CLIENT_IP'])
|| isset($_SERVER['HTTP_X_FORWARDED_FOR'])
|| !(in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1', 'fe80::1'
) {
header('HTTP/1.0 403 Forbidden');
exit('You are not allowed to access this file. Check '.basename(__FI
}
// app_dev.php
// This check prevents access to debug front controllers that are deploy
// Feel free to remove this, extend it, or make something more sophistic
if (isset($_SERVER['HTTP_CLIENT_IP'])
|| isset($_SERVER['HTTP_X_FORWARDED_FOR'])
|| !(in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1', 'fe80::1'
) {
// header('HTTP/1.0 403 Forbidden');
// exit('You are not allowed to access this file. Check '.basename(_
}
<?php //app.php
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Debug\Debug;
use Symfony\Component\ClassLoader\ApcClassLoader;
$env = getenv('SYMFONY_ENV') ?: 'prod';
$debug = 'dev' === $env;
$loader = require_once __DIR__.'/../app/bootstrap.php.cache';
if ($debug) {
Debug::enable();
}
if ('prod' === $env) {
$apcLoader = new ApcClassLoader(sha1(__FILE__), $loader);
$loader->unregister();
$apcLoader->register(true);
}
require_once __DIR__.'/../app/AppKernel.php';
$kernel = new AppKernel($env, $debug);
$kernel->loadClassCache();
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
Utiliser SYMFONY_ENV
Définir SYMFONY_ENV
# docker-compose.yml
web:
image: php:5.6-apache
environment:
- SYMFONY_ENV=dev
command: /usr/sbin/apache2ctl -D FOREGROUND
volumes:
- .:/var/www/html
# vhost.conf
<VirtualHost *:80>
DocumentRoot /var/www/html
SetEnv SYMFONY_ENV "dev"
<Directory /var/www/html>
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Boîte à outils
# docker-compose.yml
web:
image: php:5.6-apache
volumes:
- .:/var/www/html
tools:
build: ./docker/tools
volumes:
- .:/var/www/html
$ docker-compose run --rm tools bower install
$ docker-compose run --rm tools app/console assetic:dump
# Dockerfile
FROM debian:jessie
RUN apt-get update \
&& apt-get install --no-install-recommends -y \
nodejs \
npm \
php5-cli \
php5-curl \
php5-json \
php5-intl \
&& apt-get clean \
&& rm -r /var/lib/apt/lists/*
RUN ln -sf /usr/bin/nodejs /usr/bin/node \
&& npm install -g bower less
jolicode/phaudit
$ alias phaudit="docker run --rm -ti \
-v \`pwd\`:/project \
jolicode/phaudit"
$ phaudit phploc .
$ phaudit pdepend --summary-xml=summary.xml .
$ phaudit phpmd . text naming
$ phaudit phpcs .
$ phaudit phpcbf .
$ phaudit phpcpd .
$ phaudit phpdcd .
$ phaudit phpmetrics --report-cli .
$ phaudit php-cs-fixer fix .