I need to deploy many instances of the same LAMP (or LEMP) application :
- each instance will be accessible from a subdomain, with front loadbalancer/ proxy
- each instance must have its own db data and files data.
- each instance might be monitored
- memory limit / cpu might be set per app instance
- easy to automate the deployment of an new webapp instance
- environment might be easily reproducible for test and development.
Application requires :
- dameon processes (
Nginx
,MariaDB
,PHPFPM
) - binaries (
composer
,bower
, ...) - other systems specific libs & config
After reading Docker documentation and many howtos, I see different solutions to dockerize this web application :
Solution 1 : Use an all-in-one Container
All the stack is in one container :
- webapp source files, EMP daemon processes, binaries, …
- mounted volumes for
mysql
and webapp data files
Examples :
Tutum
provides an all-in-one container for Wordpress Application : https://github.com/tutumcloud/tutum-docker-wordpressPhusion
, which provides base image optimized for Docker, precises in documentation (https://github.com/phusion/baseimage-docker#docker_single_process) :Docker runs fine with multiple processes in a container. In fact, there is no technical reason why you should limit yourself to one process
Pros (IMHO) :
- Seems easy to automate deploiement, to monitor, to destroy….
- Easy to use in prod, test and dev environment.
Cons (IMHO):
- Monolithic
- Hard to scale
- Does not use all the strength of Docker
Solution 2 : Use a containers stack per webapp instance
For each webapp to deploy, a containers stack is deployed :
- One container per process :
Nginx
,Mysql
,PHP-FPM
, - Binary containers (
composer
,bower
,...) can be also dockerized, or merged in the phpfpm container - mount volumes for mysql and webapp data files
Examples :
- the orchestror tool
Gaudi
provides an example with a LEMP architecture based on 3 “daemon” containers (nginx, mysql, phpfpm), and 2 app containers (composer, bower) (http://marmelab.com/blog/2014/06/04/demo-symfony-with-docker-and-gaudi.html)
Pro (IMHO) :
- Decoupled
- processes isolated per instance
- One process per container, no need daemon manager as RUnit or Supervisord
Cons (IMHO) :
- Seems more complicated to do work
- Hard to maintain, to see a “big picture” of all containers states, links, version...
Solution 3 : Mixin the 2 previous solutions
- One “app” container with : app src files, nginx, phpfmp, composer, git..
- One container for db mysql, which can be shared or not with the app container
I'm more Dev than Ops, also it's confused for me.
So, Questions :
- What are the criteria, pros/cons to consider when choosing between theses solutions?
- Howto to manage all the containers stacks if i choose Solution 2, to have a "big picture" of all containers states, links, version... ?
- App src files (PHP) might be built in the container or mounted as volume, eg. /var/www ?