Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Docker & PHP

Docker & PHP

Szymon Skórczyński

February 18, 2016
Tweet

More Decks by Szymon Skórczyński

Other Decks in Programming

Transcript

  1. DOCKER & PHP
    development and deployment
    Szymon Skórczyński
    Schibsted Tech Polska
    PHP UK Conference
    February 18, 2016

    View full-size slide

  2. Szymon Skórczyński
    PHP Developer
    @sskorc

    View full-size slide

  3. Gdańsk, Poland

    View full-size slide

  4. WHAT MAKES DOCKER
    SO GOOD?

    View full-size slide

  5. cgroups
    namespaces

    View full-size slide

  6. 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

    View full-size slide

  7. IMAGE
    VS
    CONTAINER

    View full-size slide

  8. HOW TO DEVELOP?

    View full-size slide

  9. Host (Mac or Windows)
    Docker Client
    Docker Machine
    Docker Engine
    Container
    nginx
    Container
    Mongo

    View full-size slide

  10. DEMO #1
    RUNNING DOCKER MACHINE

    View full-size slide

  11. USE CASE #1
    TESTING PHP7

    View full-size slide

  12. DEMO #2
    TESTING PHP7

    View full-size slide

  13. USE CASE #2
    PHP APPLICATION

    View full-size slide

  14. application
    sources
    DB
    files

    View full-size slide

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

    View full-size slide

  16. FROM php:5.6.18-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

    View full-size slide

  17. FROM php:5.6.18-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

    View full-size slide

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

    View full-size slide

  19. RUN IT!
    docker-compose up -d

    View full-size slide

  20. DEMO #3
    RUNNING PHP APPLICATION

    View full-size slide

  21. HOW TO DEPLOY?

    View full-size slide

  22. php:
    image: sskorc/docker-symfony-dist:latest
    links: [db]
    volumes:
    - /var/www/docker-symfony
    nginx:
    image: nginx:1.9.10
    links: [php]
    volumes_from: [php]
    volumes:
    - /var/app/vhost.conf:/etc/nginx/conf.d/default.conf
    ports: ["80:80"]
    db:
    image: mongo:3.2.1
    volumes:
    - /var/app/db:/data/db
    ports: ["27017:27017"]
    Stackfile

    View full-size slide

  23. FROM sskorc/symfony2-mongo:latest
    ADD docker/php.ini /usr/local/etc/php/php.ini
    ADD . /var/www/docker-symfony
    RUN cd /var/www/docker-symfony && composer install -n
    WORKDIR /var/www/docker-symfony
    Dockerfile

    View full-size slide

  24. checkout
    sources
    GitHub
    AWS EC2
    node #1
    Docker Hub
    build sf2 image
    AWS EC2
    node #2
    AWS EC2
    node #n
    Tutum
    trigger
    deploy

    View full-size slide

  25. checkout
    sources
    GitHub
    AWS EC2
    node #1
    Docker Hub
    build sf2 image
    AWS EC2
    node #2
    AWS EC2
    node #n
    Tutum
    trigger
    deploy
    Travis CI
    run tests
    pull
    other images
    push
    sf2 image
    pull
    images

    View full-size slide

  26. language: ruby
    services: [docker]
    before_install:
    - docker login -e="$D_EMAIL" -u="$D_USERNAME" -p="$D_PASSWORD"
    before_script:
    - rm web/app_dev.php web/config.php web/info.php
    script:
    - docker build -f Dockerfile.remote -t sskorc/docker-symfony-dist .
    - docker-compose --file=docker-compose-remote.yml up -d
    - docker exec -it dockersymfony_php_1 bash -c "bin/phing test"
    - docker exec -it dockersymfony_php_1 bash -c "bin/phing quality"
    deploy:
    provider: script
    script: ./deploy.sh
    skip_cleanup: true
    on:
    branch: master
    .travis.yml

    View full-size slide

  27. #! /bin/bash
    docker tag sskorc/docker-symfony-dist:latest sskorc/docker-symfony-
    dist:$TRAVIS_BUILD_NUMBER
    docker push sskorc/docker-symfony-dist
    curl -u sskorc:$TUTUM_API_KEY -H "Content-Type: application/json"
    -X POST -d '{"reuse_volumes":false}' https://dashboard.tutum.co/api/
    v1/service/$PHP_SERVICE_UUID/redeploy/
    deploy.sh

    View full-size slide

  28. ARE THERE ANY
    THREATS?

    View full-size slide

  29. SOME THREATS
    Garbage collection
    Persistence
    Stability
    Maturity

    View full-size slide

  30. SHOULD YOU TRY DOCKER?

    View full-size slide

  31. WHY?
    Portability
    Isolation
    Performance
    Modularity
    Community

    View full-size slide

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

    View full-size slide