dockerize your symfony application - symfony live nyc 2014

31
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

Upload: andre-romcke

Post on 17-Feb-2017

514 views

Category:

Software


5 download

TRANSCRIPT

Page 1: Dockerize your Symfony application - Symfony Live NYC 2014

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

Page 2: Dockerize your Symfony application - Symfony Live NYC 2014

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

Page 3: Dockerize your Symfony application - Symfony Live NYC 2014

What is Docker?

Page 4: Dockerize your Symfony application - Symfony Live NYC 2014

What is Docker?

Environment as Micro services ! LEGO for developers?

..

Page 5: Dockerize your Symfony application - Symfony Live NYC 2014

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.

..

Page 6: Dockerize your Symfony application - Symfony Live NYC 2014

Concept: Layers

..

“Docker Engine”

However lets use a more relevant example…

Page 7: Dockerize your Symfony application - Symfony Live NYC 2014

Concept: Layers

..

PHP-CLI ContainerPHP-FPM ContainerNginx ContainerMySQL Container

PHP ImageBase Image

Nginx ImageMySQL ImagePHP-CLI ImagePHP-FPM Image

PHP ImageBase Image Base Image Base Image

FS/DB Volum Container

Base Image

Container layer Container layerContainer layer Container layer

Container layer

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

Page 8: Dockerize your Symfony application - Symfony Live NYC 2014

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"]

Page 9: Dockerize your Symfony application - Symfony Live NYC 2014

• 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

Page 10: Dockerize your Symfony application - Symfony Live NYC 2014

• 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

Page 11: Dockerize your Symfony application - Symfony Live NYC 2014

• 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

Page 12: Dockerize your Symfony application - Symfony Live NYC 2014

• 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

Page 13: Dockerize your Symfony application - Symfony Live NYC 2014

• 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/wwwrw

www-1 :80

www-2 :80

sf-vol

db-1 :3306

Varnish :80

Page 14: Dockerize your Symfony application - Symfony Live NYC 2014

How does it compare to VM’s?

Virtual Machines vs Docker

App A App BBin/Libs Bin/Libs

Guest OS Guest OS

HyperVisorHost OSServer

App A App BBin/Libs Bin/Libs

Guest OS Guest OS“Docker Engine”

Host OSServer

Page 15: Dockerize your Symfony application - Symfony Live NYC 2014

How does it compare to VM’s?

Virtual Machines vs Docker

App A App BBin/Libs Bin/Libs

Guest OS Guest OS

HyperVisorHost OSServer

App A App BBin/Libs Bin/Libs

Guest OS Guest OS“Docker Engine”

Host OSServerClose

to zero run time overhead!

Page 16: Dockerize your Symfony application - Symfony Live NYC 2014

How does it compare to VM’s?

App A App BBin/Libs Bin/Libs

Guest OS Guest OS“Docker Engine”

Host OSServer

Virtual Machines vs Docker

App A App BBin/Libs Bin/Libs

Guest OS Guest OS

HyperVisorHost OSServer

“Machine” boots in less then

a second

Close to zero run time

overhead!

Page 17: Dockerize your Symfony application - Symfony Live NYC 2014

App A App BBin/Libs Bin/Libs

Guest OS Guest OS“Docker Engine”

Host OSServer

How does it compare to VM’s?

Virtual Machines vs Docker

App A App BBin/Libs Bin/Libs

Guest OS Guest OS

HyperVisorHost OSServer Close

to zero run time overhead!

Shared “layers” share

memory

“Machine” boots in less then

a second

Page 18: Dockerize your Symfony application - Symfony Live NYC 2014

App A App BBin/Libs Bin/Libs

Guest OS Guest OS“Docker Engine”

Host OSServer

How does it compare to VM’s?

Virtual Machines vs Docker

App A App BBin/Libs Bin/Libs

Guest OS Guest OS

HyperVisorHost OSServer 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

Page 19: Dockerize your Symfony application - Symfony Live NYC 2014

Why use Docker?

Page 20: Dockerize your Symfony application - Symfony Live NYC 2014

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

Page 21: Dockerize your Symfony application - Symfony Live NYC 2014

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.

Page 22: Dockerize your Symfony application - Symfony Live NYC 2014

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…

Page 23: Dockerize your Symfony application - Symfony Live NYC 2014

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

..

Page 24: Dockerize your Symfony application - Symfony Live NYC 2014

Examples of use and CI/CD

Page 25: Dockerize your Symfony application - Symfony Live NYC 2014

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

Page 26: Dockerize your Symfony application - Symfony Live NYC 2014

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

Page 27: Dockerize your Symfony application - Symfony Live NYC 2014

Example: Single app, several nodesWeb 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 demand

Page 28: Dockerize your Symfony application - Symfony Live NYC 2014

Example: Multiple apps, several nodes “PAAS”Web Server / VM 1

load-balancer

Data-base

Binary storage

Adding nodes

on demand

App Nwww

sf-vol

php-fpm

redis

App 3www

sf-vol

php-fpm

redis

App 4www

sf-vol

php-fpm

redis

App 1www

sf-vol

php-fpm

redis

App 2www

sf-vol

php-fpm

redis

Web Server / VM 2

App Nwww

sf-vol

php-fpm

redis

App 3www

sf-vol

php-fpm

redis

App 4www

sf-vol

php-fpm

redis

App 1www

sf-vol

php-fpm

redis

App 2www

sf-vol

php-fpm

redis

Web Server / VM 3 App 3www

sf-vol

php-fpm

redis

Page 29: Dockerize your Symfony application - Symfony Live NYC 2014

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?

Page 30: Dockerize your Symfony application - Symfony Live NYC 2014

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”

Page 31: Dockerize your Symfony application - Symfony Live NYC 2014

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