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
Who am I? André Rømcke: • Heads Engineering (Dev, QA & Support) at eZ Systems AS • PHP for 9 years, started with frontend in 96 <blink>#dhtml</blink> • 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
What is Docker?
What is Docker? Environment as Micro services ! LEGO for developers?
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.
Concept: Layers “Docker Engine” However lets use a more relevant example…
Concept: Layers PHP-CPHP-FPM ContainerNginx ContainerMySQL Container PHP Image Base Image Nginx ImageMySQL 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
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"]
• 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
• 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
• 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
• 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-volrw Varnish
 :80
• 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
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 Bin/Libs Guest OS 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 App A App B Bin/Libs Bin/Libs Guest OS Guest OS “Docker Engine” Host OS ServerClose to zero run time overhead!
How does it compare to VM’s? App A App B Bin/Libs Bin/Libs Guest OS Guest OS “Docker Engine” Host OS Server 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!
App A App B Bin/Libs Bin/Libs Guest OS 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
App A App B Bin/Libs Bin/Libs Guest OS 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
Why use Docker?
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
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.
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…
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
Examples of use and CI/CD
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
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
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
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
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?
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”
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

Dockerize your Symfony application - Symfony Live NYC 2014

  • 1.
    Dockerize your Symfonyapplication Docker: What, Why and How with Symfony? Symfony Live New York, Oct 9-10 2014! By @andrerom, VP Engineering at eZ Systems AS
  • 2.
    Who am I? AndréRømcke: • Heads Engineering (Dev, QA & Support) at eZ Systems AS • PHP for 9 years, started with frontend in 96 <blink>#dhtml</blink> • 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
  • 3.
  • 4.
    What is Docker? Environmentas Micro services ! LEGO for developers?
  • 5.
    What is Docker? Currentlyon 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.
  • 6.
    Concept: Layers “Docker Engine” Howeverlets use a more relevant example…
  • 7.
    Concept: Layers PHP-CPHP-FPM ContainerNginxContainerMySQL Container PHP Image Base Image Nginx ImageMySQL 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
  • 8.
    Concept: DockerFile • Definesa 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"]
  • 9.
    • Just likeyou 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
  • 10.
    • Just likeyou 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
  • 11.
    • Shares exposedports 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
  • 12.
    • Mounts afolder 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-volrw Varnish
 :80
  • 13.
    • Mounts allvolumes 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
  • 14.
    How does itcompare 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 Bin/Libs Guest OS Guest OS “Docker Engine” Host OS Server
  • 15.
    How does itcompare 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 Bin/Libs Guest OS Guest OS “Docker Engine” Host OS ServerClose to zero run time overhead!
  • 16.
    How does itcompare to VM’s? App A App B Bin/Libs Bin/Libs Guest OS Guest OS “Docker Engine” Host OS Server 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!
  • 17.
    App A AppB Bin/Libs Bin/Libs Guest OS 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
  • 18.
    App A AppB Bin/Libs Bin/Libs Guest OS 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
  • 19.
  • 20.
    Why? Docker holds thepromise 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
  • 21.
    Example: Not unrealisticthat 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.
  • 22.
    Why? Highly scalable: • “Byforcing 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…
  • 23.
    High level Benefits LetsDevelopers 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
  • 24.
    Examples of useand CI/CD
  • 25.
    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
  • 26.
    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
  • 27.
    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
  • 28.
    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
  • 29.
    Continues Integration andDeployment? Docker Hub (Public/Private)All tests merge publish image symfony-standard pull latests stable parent image Symfony-standard on Docker Hub?
  • 30.
    Continues Integration andDeployment? 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”
  • 31.
    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