Geoffrey Bachelet – @ubermuda
A multi-container Symfony2 setup
with Docker.
Slide 2
Slide 2 text
Container Engine?
Based on the Linux kernel's LXC instructions
Processes and resources isolation
"chroot" on steroids / super lightweight VMs
Slide 3
Slide 3 text
Host OS
Hypervisor
Guest
OS
Guest
OS
Guest
OS
Guest
OS
App App App App
Host OS
Docker + LXC
App App App App
VMs vs Containers
Slide 4
Slide 4 text
Host OS
Hypervisor
Guest
OS
Guest
OS
Guest
OS
Guest
OS
App App App App
Host OS
Docker + LXC
App App App App
VMs vs Containers
Slide 5
Slide 5 text
VMs vs Containers
LXC / Jails / Zones / etc
Uses the host's kernel
Boots in seconds
0 overhead (almost)
Easy to pass around
Hypervisor
Boots a complete OS
Boots in minutes
Guest OS' overhead
Several Go images
$
cd
/project
project
$
bin/start
Loading
composer
repositories
with
package
information
Installing
dependencies
(including
require-‐dev)
from
lock
file
...
symfony2
├──
Dockerfile
├──
entrypoint.sh
├──
my.cnf
├──
php.ini
├──
services
│
├──
mysql
│
│
└──
run
│
├──
nginx
│
│
└──
run
│
└──
php5-‐fpm
│
└──
run
└──
vhost.conf
#!/bin/bash
-‐e
!
if
[
!
-‐d
/var/www
];
then
echo
'No
application
found
in
/var/www'
exit
1;
fi
!
cd
/var/www
!
if
[
!
-‐d
vendor
];
then
composer
install
fi
!
if
[
-‐f
./init.sh
];
then
./init.sh
fi
!
exec
svscan
/srv/services
Slide 42
Slide 42 text
symfony2
├──
Dockerfile
├──
entrypoint.sh
├──
my.cnf
├──
php.ini
├──
services
│
├──
mysql
│
│
└──
run
│
├──
nginx
│
│
└──
run
│
└──
php5-‐fpm
│
└──
run
└──
vhost.conf
#!/bin/bash
-‐e
!
if
[
!
-‐d
/var/www
];
then
echo
'No
application
found
in
/var/www'
exit
1;
fi
!
cd
/var/www
!
if
[
!
-‐d
vendor
];
then
composer
install
fi
!
if
[
-‐f
./init.sh
];
then
./init.sh
fi
!
exec
svscan
/srv/services
Slide 43
Slide 43 text
symfony2
├──
Dockerfile
├──
entrypoint.sh
├──
my.cnf
├──
php.ini
├──
services
│
├──
mysql
│
│
└──
run
│
├──
nginx
│
│
└──
run
│
└──
php5-‐fpm
│
└──
run
└──
vhost.conf
#!/bin/bash
-‐e
!
if
[
!
-‐d
/var/www
];
then
echo
'No
application
found
in
/var/www'
exit
1;
fi
!
cd
/var/www
!
if
[
!
-‐d
vendor
];
then
composer
install
fi
!
if
[
-‐f
./init.sh
];
then
./init.sh
fi
!
exec
svscan
/srv/services
Slide 44
Slide 44 text
symfony2
├──
Dockerfile
├──
entrypoint.sh
├──
my.cnf
├──
php.ini
├──
services
│
├──
mysql
│
│
└──
run
│
├──
nginx
│
│
└──
run
│
└──
php5-‐fpm
│
└──
run
└──
vhost.conf
#!/bin/bash
-‐e
!
if
[
!
-‐d
/var/www
];
then
echo
'No
application
found
in
/var/www'
exit
1;
fi
!
cd
/var/www
!
if
[
!
-‐d
vendor
];
then
composer
install
fi
!
if
[
-‐f
./init.sh
];
then
./init.sh
fi
!
exec
svscan
/srv/services
Slide 45
Slide 45 text
symfony2
├──
Dockerfile
├──
entrypoint.sh
├──
my.cnf
├──
php.ini
├──
services
│
├──
mysql
│
│
└──
run
│
├──
nginx
│
│
└──
run
│
└──
php5-‐fpm
│
└──
run
└──
vhost.conf
#!/bin/bash
-‐e
!
if
[
!
-‐d
/var/www
];
then
echo
'No
application
found
in
/var/www'
exit
1;
fi
!
cd
/var/www
!
if
[
!
-‐d
vendor
];
then
composer
install
fi
!
if
[
-‐f
./init.sh
];
then
./init.sh
fi
!
exec
svscan
/srv/services
$
cd
/project
project
$
bin/start
Loading
composer
repositories
with
package
information
Installing
dependencies
(including
require-‐dev)
from
lock
file
...
Slide 54
Slide 54 text
No content
Slide 55
Slide 55 text
No content
Slide 56
Slide 56 text
Host OS
THE INTERNET
container
nginx
mysql php5-fpm
Slide 57
Slide 57 text
Multi-container setup
Slide 58
Slide 58 text
Host OS
THE INTERNET
nginx
mysql php5-fpm
/var/www
/var/lib/mysql
Slide 59
Slide 59 text
Containers links
Slide 60
Slide 60 text
$
docker
run
-‐-‐name
redis
sflive/redis
!
$
docker
run
-‐-‐link
redis:foo
sflive/symfony2
Slide 61
Slide 61 text
$
docker
run
-‐-‐name
redis
sflive/redis
!
$
docker
run
-‐-‐link
redis:foo
sflive/symfony2
Slide 62
Slide 62 text
$
docker
run
-‐-‐name
redis
sflive/redis
!
$
docker
run
-‐-‐link
redis:foo
sflive/symfony2
#!/bin/bash
-‐e
for
name
in
$(find
-‐maxdepth
1
!
-‐path
.
-‐type
d);
do
docker
build
-‐t
sflive/$(basename
$name)
-‐-‐rm
$name
done;
Slide 81
Slide 81 text
No content
Slide 82
Slide 82 text
$
docker
run
-‐name
data
sflive/data
!
$
docker
run
-‐-‐volumes-‐from
data
-‐name
mysql
sflive/mysql
!
$
docker
run
-‐v
$(pwd):/var/www
-‐name
php5
sflive/php5
!
$
docker
run
-‐p
80:80
-‐v
$(pwd):/var/www
\
-‐link
php5:php5
\
-‐link
mysql:mysql
\
sflive/nginx
Slide 83
Slide 83 text
$
docker
run
-‐name
data
sflive/data
!
$
docker
run
-‐-‐volumes-‐from
data
-‐name
mysql
sflive/mysql
!
$
docker
run
-‐v
$(pwd):/var/www
-‐name
php5
sflive/php5
!
$
docker
run
-‐p
80:80
-‐v
$(pwd):/var/www
\
-‐link
php5:php5
\
-‐link
mysql:mysql
\
sflive/nginx
Slide 84
Slide 84 text
$
docker
run
-‐name
data
sflive/data
!
$
docker
run
-‐-‐volumes-‐from
data
-‐name
mysql
sflive/mysql
!
$
docker
run
-‐v
$(pwd):/var/www
-‐name
php5
sflive/php5
!
$
docker
run
-‐p
80:80
-‐v
$(pwd):/var/www
\
-‐link
php5:php5
\
-‐link
mysql:mysql
\
sflive/nginx
Slide 85
Slide 85 text
No content
Slide 86
Slide 86 text
No content
Slide 87
Slide 87 text
And more!
• docker run -d, attach, logs, top, ...
• Orchestration (Gaudi, Fig, ...)
• Docker Index
• Docker Remote API (dockerode, Docker-PHP, ...)
• Dockerfile: USER, WORKDIR, ONBUILD, ...
• ...
Slide 88
Slide 88 text
Recap.
• Image: like a VM image. Contains the hard-drive
(rootfs) and some configuration.
• Container: a running instance of an image.
Slide 89
Slide 89 text
• You can commit a terminated container, and you get
a re-usable image representing the state of that
container.
• Volumes are like shared directories. Containers can
share zero or many volumes.
• Containers can be linked to one another.
Recap.