Pro Yearly is on sale from $80 to $50! »

Docker & PHP

Docker & PHP

Efa1d75eaaafa76ef74a9310bc58fcf8?s=128

Szymon Skórczyński

February 18, 2016
Tweet

Transcript

  1. DOCKER & PHP development and deployment Szymon Skórczyński Schibsted Tech

    Polska PHP UK Conference February 18, 2016
  2. Szymon Skórczyński PHP Developer @sskorc

  3. Gdańsk, Poland

  4. None
  5. None
  6. WHAT MAKES DOCKER SO GOOD?

  7. None
  8. None
  9. cgroups namespaces

  10. None
  11. None
  12. 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
  13. None
  14. None
  15. None
  16. IMAGE VS CONTAINER

  17. HOW TO DEVELOP?

  18. LINUX

  19. Host (Mac or Windows) Docker Client Docker Machine Docker Engine

    Container nginx Container Mongo
  20. DEMO #1 RUNNING DOCKER MACHINE

  21. USE CASE #1 TESTING PHP7

  22. DEMO #2 TESTING PHP7

  23. USE CASE #2 PHP APPLICATION

  24. application sources DB files

  25. 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
  26. 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
  27. 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
  28. FROM sskorc/symfony2-mongo:latest ADD docker/php.ini /usr/local/etc/php/php.ini WORKDIR /var/www/docker-symfony Dockerfile

  29. RUN IT! docker-compose up -d

  30. DEMO #3 RUNNING PHP APPLICATION

  31. HOW TO DEPLOY?

  32. None
  33. None
  34. IaaS

  35. None
  36. None
  37. None
  38. None
  39. None
  40. 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
  41. None
  42. None
  43. None
  44. 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
  45. checkout sources GitHub AWS EC2 node #1 Docker Hub build

    sf2 image AWS EC2 node #2 AWS EC2 node #n Tutum trigger deploy
  46. 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
  47. 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
  48. #! /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
  49. None
  50. ARE THERE ANY THREATS?

  51. SOME THREATS Garbage collection Persistence Stability Maturity

  52. WRAP UP

  53. SHOULD YOU TRY DOCKER?

  54. WHY? Portability Isolation Performance Modularity Community

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