Slide 1

Slide 1 text

DOCKER & PHP development and deployment Szymon Skórczyński Schibsted Tech Polska PHPCon Poland November 13, 2015

Slide 2

Slide 2 text

Szymon Skórczyński PHP Developer @sskorc

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

WHAT MAKES DOCKER SO GOOD?

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

Host OS Hypervisor Guest OS Guest OS Guest OS bins/libs bins/libs bins/libs App A App A` App B Host OS Docker bins/libs bins/libs App A App A’ App B App B’ App B’ App B’ VM Docker container Docker Standard VM

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

IMAGE VS CONTAINER

Slide 15

Slide 15 text

HOW TO DEVELOP?

Slide 16

Slide 16 text

LINUX

Slide 17

Slide 17 text

Host (Mac or Windows) Docker Client Docker Machine Docker Engine Container Apache Container Mongo

Slide 18

Slide 18 text

applicaction sources DB files

Slide 19

Slide 19 text

php: build: . links: [db] volumes: - .:/var/www/docker-symfony nginx: image: nginx:1.9.6 links: [php] volumes_from: [php] volumes: - ./docker/vhost.conf:/etc/nginx/conf.d/default.conf ports: ["80:80"] db: image: mongo:3.0.7 volumes: - /mnt/sda1/var/lib/mongo-data:/data/db ports: ["27017:27017"] docker-compose.yml

Slide 20

Slide 20 text

FROM php:5.6.15-fpm RUN apt-get update \ && curl -sL https://deb.nodesource.com/setup | bash - \ && apt-get install -y git libssl-dev zlib1g-dev libicu-dev g++ \ && pecl install mongo \ && echo extension=mongo.so > /usr/local/etc/php/conf.d/mongo.ini \ && pecl install apcu-beta \ && echo extension=apcu.so > /usr/local/etc/php/conf.d/apcu.ini \ && docker-php-ext-install zip mbstring intl RUN curl -sS https://getcomposer.org/installer | php \ && mv composer.phar /usr/bin/composer ADD docker/php.ini /usr/local/etc/php/php.ini WORKDIR /var/www/docker-symfony Dockerfile

Slide 21

Slide 21 text

FROM php:5.6.15-fpm RUN apt-get update \ && curl -sL https://deb.nodesource.com/setup | bash - \ && apt-get install -y git libssl-dev zlib1g-dev libicu-dev g++ \ && pecl install mongo \ && echo extension=mongo.so > /usr/local/etc/php/conf.d/mongo.ini \ && pecl install apcu-beta \ && echo extension=apcu.so > /usr/local/etc/php/conf.d/apcu.ini \ && docker-php-ext-install zip mbstring intl RUN curl -sS https://getcomposer.org/installer | php \ && mv composer.phar /usr/bin/composer ADD docker/php.ini /usr/local/etc/php/php.ini WORKDIR /var/www/docker-symfony Dockerfile

Slide 22

Slide 22 text

FROM sskorc/symfony2-mongo:latest ADD docker/php.ini /usr/local/etc/php/php.ini WORKDIR /var/www/docker-symfony Dockerfile

Slide 23

Slide 23 text

RUN IT! docker-compose up -d

Slide 24

Slide 24 text

DEMO

Slide 25

Slide 25 text

HOW TO DEPLOY?

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

THE STEPS 1. Create a specific IAM policy and assing it to the role 2. Create a new environment with “Multi-container Docker” predifined configuration 3. Assign a proper role to the environment 4. Prepare the Dockerrun.aws.json file 5. Deploy!

Slide 28

Slide 28 text

{ "AWSEBDockerrunVersion": 2, "authentication": { "bucket": "docker-symfony", "key": "docker/dockercfg" }, "volumes": [ { "name": "data", "host": { "sourcePath": "/var/data" } }, { "name": "symfony-app", "host": { "sourcePath": "/var/app/current" } }, { "name": "vhost-config", "host": { "sourcePath": "/var/app/current/docker/vhost.conf" } } ],

Slide 29

Slide 29 text

"containerDefinitions": [{ "name": "db", "image": "mongo:3.0.7", "essential": true, "memory": 256, "mountPoints": [{ "sourceVolume": "data", "containerPath": "/data/db" }] }, { "name": "php", "image": "sskorc/docker-symfony:latest", "essential": true, "memory": 256, "links": ["db"], "mountPoints": [{ "sourceVolume": "symfony-app", "containerPath": "/var/www/docker-symfony" }] },

Slide 30

Slide 30 text

{ "name": "nginx", "image": "nginx:1.9.6", "essential": true, "memory": 256, "portMappings": [{ "hostPort": 80, "containerPort": 80 }], "links": ["php"], "mountPoints": [{ "sourceVolume": "symfony-app", "containerPath": "/var/www/docker-symfony" }, { "sourceVolume": "vhost-config", "containerPath": "/etc/nginx/conf.d/default.conf" }] } ] } Dockerrun.aws.json

Slide 31

Slide 31 text

option_settings: - namespace: aws:elasticbeanstalk:command option_name: Timeout value: 1200 commands: 01_docker_clean_containers: command: docker rm -v $(docker ps -a -q) ignoreErrors: true 02_docker_clean_images: command: docker rmi $(docker images -q) ignoreErrors: true .ebextensions/01docker.config

Slide 32

Slide 32 text

checkout sources push sf2 image pull sf2 image, mongo image, nginx image GitHub CircleCI AWS Docker Hub build sf2 image run tests on sf2 image send sources and fire! pull mongo image run sf2 image, mongo image, nginx image

Slide 33

Slide 33 text

checkout sources push sf2 image pull sf2 image, mongo image, nginx image GitHub CircleCI AWS Docker Hub build sf2 image run tests on sf2 image send sources and fire! pull mongo image run sf2 image, mongo image, nginx image

Slide 34

Slide 34 text

checkout sources push sf2 image pull sf2 image, mongo image, nginx image GitHub CircleCI AWS Docker Hub build sf2 image run tests on sf2 image send sources and fire! pull mongo image run sf2 image, mongo image, nginx image APPLICATION_VERSION=$ENVIRONMENT-$BUILD_NUM-docker-symfony.zip zip $APPLICATION_VERSION -r . aws s3 cp $APPLICATION_VERSION s3://$EB_BUCKET/$APPLICATION_VERSION aws elasticbeanstalk create-application-version --application-name "docker-symfony" \ --version-label $BUILD_NUM --source-bundle S3Bucket= $EB_BUCKET,S3Key=$APPLICATION_VERSION aws elasticbeanstalk update-environment --environment-name $ENVIRONMENT \ --version-label $BUILD_NUM

Slide 35

Slide 35 text

checkout sources push sf2 image pull sf2 image, mongo image, nginx image GitHub CircleCI AWS Docker Hub build sf2 image run tests on sf2 image send sources and fire! pull mongo image run sf2 image, mongo image, nginx image

Slide 36

Slide 36 text

No content

Slide 37

Slide 37 text

EC2 Container Service

Slide 38

Slide 38 text

WRAP UP

Slide 39

Slide 39 text

SHOULD YOU TRY DOCKER?

Slide 40

Slide 40 text

WHY? Portability Isolation Performance Modularity Community

Slide 41

Slide 41 text

https://github.com/sskorc/docker-symfony http://www.schibsted.pl/category/devops/ @sskorc https://joind.in/16069