Slide 1

Slide 1 text

Dockerize your Symfony application Docker: What, Why and How with Symfony? Symfony Live New York, Oct 9-10 2014! By @andrerom, VP Engineering at eZ Systems AS

Slide 2

Slide 2 text

Who am I? André Rømcke: • Heads Engineering (Dev, QA & Support) at eZ Systems AS • PHP for 9 years, started with frontend in 96 #dhtml • Currently living in Lyon, France but from ~Oslo, Norway ! eZ Systems AS: • Maker of eZ Publish since 2001 • Norwegian based but with offices in 7 countries and hiring • Professional partners & Community users in all corners of the world ! eZ Publish • A Open source Enterprise Content Management System • Started using Symfony in 2012 (5.0), will complete the migration to Symfony in 2015 (6.0) with new product name: eZ Platform

Slide 3

Slide 3 text

What is Docker?

Slide 4

Slide 4 text

What is Docker? Environment as Micro services ! LEGO for developers?

Slide 5

Slide 5 text

What is Docker? Currently on docker.com: “Docker - An open platform for distributed applications for developers and sysadmins.” ! ! Docker Engine is built on LXC ( cgroups, namespaces, Apparmor/SELinux, …) and Union file system to provide a layered container image format that can run on any recent Linux distro. ! Docker Hub is a cloud service for sharing container images and automating workflows, free for public, paid for private.

Slide 6

Slide 6 text

Concept: Layers “Docker Engine” However lets use a more relevant example…

Slide 7

Slide 7 text

Concept: Layers PHP-C PHP-FPM Container Nginx Container MySQL Container PHP Image Base Image Nginx Image MySQL Image PHP- PHP-FPM Image PH Base Image Base Image Bas m e Container layer Container layer Container layer Conta yer Example: $ sudo docker run -d php-fpm:5.6 ! ! ! ! ! ! ! • Starts a php-fpm container based on a php-fpm image tagged “5.6”
 • The php-fpm image extends a plain php image, which again extends a base image like debian/ubuntu/centos
 • You can write to file system inside container, but changes in container is not persisted when replaced with new version of image unless using volumes

Slide 8

Slide 8 text

Concept: DockerFile • Defines a Docker image • A bit like VagrantFile meets Puppet/Chef/Anisibel, but using shell ! • $ sudo docker build -t apache .
 FROM debian:wheezy MAINTAINER Some Maintainer "docker-maint@docker" ! RUN apt-get -y install apache2 ! ENV APACHE_RUN_USER www-data ENV APACHE_RUN_GROUP www-data ENV APACHE_LOG_DIR /var/log/apache2 ! EXPOSE 80 ! CMD ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]

Slide 9

Slide 9 text

• Just like you are used to with Vagrant or VM’s you can map ports to keep images generic ! • $ sudo docker run -d -p 81:80 —name=web-1 php:5.6-apache Host! Listen: 80 Concept: Port Mapping *:80 80 81 82 www-1
 :80 www-2
 :80 Varnish
 :80 Note: no advantage having more then one www instance other then for cluster testing on one node

Slide 10

Slide 10 text

• Just like you are used to with Vagrant or VM’s you can map ports to keep images generic ! • $ sudo docker run -d -p 81:80 —name=web-1 php:5.6-apache VM! Listen: 80 8080 localhost:8080 Concept: Port Mapping 80 81 82 www-1
 :80 www-2
 :80 Varnish
 :80 Note: no advantage having more then one www instance other then for cluster testing on one node

Slide 11

Slide 11 text

• Shares exposed ports and environment variables from one container to another ! • $ sudo docker run -d -p 81:80 --link db-1:db (…) VM! Listen: 80 Concept: Container Linking 8080 localhost:8080 80 81 82 www-1
 :80 www-2
 :80 db-1
 :3306 Varnish
 :80

Slide 12

Slide 12 text

• Mounts a folder in Host/VM to a container • Can be read only or read-write ! • $ sudo docker run -v /vagrant/www:/www:rw —name=sf-vol (…) VM! Listen: 80 Concept: Data Volume 8080 localhost:8080 vagrant/files/www 80 81 82 www-1
 :80 www-2
 :80 db-1
 :3306 sf-vol rw Varnish
 :80

Slide 13

Slide 13 text

• Mounts all volumes in one container to others • Can be read only or read-write ! • $ sudo docker run -d -p 81:80 --volumes-from sf-vol (…) VM! Listen: 80 Concept: Sharing Data Volume 80 81 82 8080 localhost:8080 vagrant/files/www rw www-1
 :80 www-2
 :80 sf-vol db-1
 :3306 Varnish
 :80

Slide 14

Slide 14 text

How does it compare to VM’s? Virtual Machines vs Docker App A App B Bin/Libs Bin/Libs Guest OS Guest OS HyperVisor Host OS Server App A App B Bin/Libs Guest OS “Docker Engine” Host OS Server

Slide 15

Slide 15 text

App A App B Bin/Libs Guest OS “Docker Engine” Host OS Server How does it compare to VM’s? Virtual Machines vs Docker App A App B Bin/Libs Bin/Libs Guest OS Guest OS HyperVisor Host OS Server Close to zero run time overhead!

Slide 16

Slide 16 text

App A App B Bin/Libs Guest OS “Docker Engine” Host OS Server How does it compare to VM’s? Virtual Machines vs Docker App A App B Bin/Libs Bin/Libs Guest OS Guest OS HyperVisor Host OS Server “Machine” boots in less then a second Close to zero run time overhead!

Slide 17

Slide 17 text

App A App B Bin/Libs Guest OS “Docker Engine” Host OS Server How does it compare to VM’s? Virtual Machines vs Docker App A App B Bin/Libs Bin/Libs Guest OS Guest OS HyperVisor Host OS Server Close to zero run time overhead! Shared “layers” share memory “Machine” boots in less then a second

Slide 18

Slide 18 text

App A App B Bin/Libs Guest OS “Docker Engine” Host OS Server How does it compare to VM’s? Virtual Machines vs Docker App A App B Bin/Libs Bin/Libs Guest OS Guest OS HyperVisor Host OS Server Close to zero run time overhead! Image size advantage; i.e. OS image only downloaded once Shared “layers” share memory “Machine” boots in less then a second

Slide 19

Slide 19 text

Why use Docker?

Slide 20

Slide 20 text

Why? Docker holds the promise of: • Stable official containers for everything* you need on Docker Hub • No need to care about OS/Linux-distro differences anymore • Develop once, use and deploy everywhere • Less need for using abstracted install recipes using Puppet/Chef/ Ansible** • Can replace capistrano, capifony, …. ! ! ! ! * Not yet, but getting there. Example: v1 of PHP container out recently ** However they are still very valid for configuration of your app

Slide 21

Slide 21 text

Example: Not unrealistic that we will have a standard docker config ala fig which can be used on: Azure, Google Computer, Server, localhost, … ! How fig.yml currently looks like: web-1: image: php:5.6-apache ports: - "80:80" links: - db-1 volumes: - /vagrant/volumes/ezpublish:/var/www:rw db-1: image: mysql:5.6 environment: MYSQL_ROOT_PASSWORD: mysecretpassword Why? Check out Google Kubernetes!
 Already supported by Google and Azure.

Slide 22

Slide 22 text

Why? Highly scalable: • “By forcing you to split out application in micro services it allows you to scale up part of the application very easily!”
 
 GOTO: • Google Kubernetes (for use on own, Azure or GoogleCloudPlatform) • Apache Mesos + Marathon • …Docker slides from DockerCon for more alternatives…

Slide 23

Slide 23 text

High level Benefits Lets Developers iterate on environment like on code: • Develop & Use locally • Use for test system keeping test server clean • Deploy/Deliver to Ops/Sysadmins • $um: Run everywhere ! Allows Ops/Sysadmins to standardize around containers: • Can focus on maintain hosts, scaling, monitoring • Streamlined Deployments ! Benefits for your business: • Standardize environments & deployments across developers, whole organization and customers • Opportunity: new marketplace for your application • Operation Cost

Slide 24

Slide 24 text

Examples of use and CI/CD

Slide 25

Slide 25 text

Example: Single app, one node Server / VM Varnish www-1 sf-vol db-vol php- fpm-1 db-1 Example of this: Note for running Symfony-standard on this: • Rename app.php or app_dev.php to index.php, or change the rewrite rules • VagrantFile: Comment out d.run command for ezpublish:prepare • Correct settings in files/vagrant.yml

Slide 26

Slide 26 text

Example: Single app, Cluster testing on one node Server / VM Varnish www-1 www-2 php- fpm-2 sf-vol db-vol php- fpm-1 db-1

Slide 27

Slide 27 text

Example: Single app, several nodes Web Server / VM 1 www-1 sf-vol php- fpm-1 redis-1 load- balancer Data- base Binary storage Web Server / VM 2 www-2 sf-vol php- fpm-2 redis-2 Web Server / VM 3 sf-vol Adding nodes on dem and

Slide 28

Slide 28 text

Example: Multiple apps, several nodes “PAAS” Web Server / VM 1 load- balancer Data- base Binary storage Adding nodes on dem and App N www sf-vol php- fpm redis App 3 www sf-vol php- fpm redis App 4 www sf-vol php- fpm redis App 1 www sf-vol php- fpm redis App 2 www sf-vol php- fpm redis Web Server / VM 2 App N www sf-vol php- fpm redis App 3 www sf-vol php- fpm redis App 4 www sf-vol php- fpm redis App 1 www sf-vol php- fpm redis App 2 www sf-vol php- fpm redis Web Server / VM 3 App 3 www sf-vol php- redis

Slide 29

Slide 29 text

Continues Integration and Deployment? Docker Hub (Public/Private) All tests merge publish image symfony-standard pull latests stable parent image Symfony-standard on Docker Hub?

Slide 30

Slide 30 text

Continues Integration and Deployment? Own containers (optional) Docker Hub (Public/Private) merge publish image Code Test on stable image merge deploy updated image Server / ! Azure /! Google Cloud /! … pull latests stable code Custom project Test on stable code pull latests stable image Note: Also checkout Pablo Godel’s talk “Rock Solid Deployment of Symfony Apps”

Slide 31

Slide 31 text

The End Resources: • registry.hub.docker.com (Official and community made containers) • github.com/ezsystems/ezpublish-docker (referred to in slides) • ez.no/Blog/What-is-Docker-and-why-should-I-care ! • Running Docker on cluster: • https://github.com/GoogleCloudPlatform/kubernetes • mesosphere.com/learn/ • aws.amazon.com/blogs/aws/container-computing/ ! Twitter: @andrerom Joined.in: https://joind.in/12188 ! PS: eZ launches 100% Symfony CMS in 2015 called eZ Platform based on todays “New/Symfony stack” in eZ Publish 5.x