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

Docker & PHP

Docker & PHP

Efa1d75eaaafa76ef74a9310bc58fcf8?s=128

Szymon Skórczyński

December 15, 2014
Tweet

Transcript

  1. DOCKER The future of web apps deployment Szymon Skórczyński Schibsted

    Tech Polska PHPers Tricity December 15, 2014
  2. ONCE UPON A TIME…

  3. TODAY

  4. TOP PROBLEMS Isolation from host OS and other environments Traceability

    of configuration changes Portability to share with colleagues and deploy easily
  5. YESTERDAY’S SOLUTION Virtualization Provisioning Orchestration

  6. GOOD, BUT NOT PERFECT

  7. TODAY’S SOLUTION

  8. KEY FACTS • written in Go in dotCloud, a PaaS

    provider • became open source in March 2013 • in June 2014 released stable ver. 1.0 • current version is 1.4
  9. POPULARITY angular.js laravel symfony ansible vagrant chef puppet 0 10

    000 20 000 30 000 40 000 2 779 3 186 8 088 8 518 9 274 13 251 17 092 32 145 Number of stars on GitHub (November 28, 2014) docker
  10. PARTNERS

  11. THE METAPHOR

  12. None
  13. HOW DOES IT WORK?

  14. THE ECOSYSTEM Image is like OVF or ISO Container is

    a running image Repository is a place to store images
  15. THE DIFFERENCE 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 VMs
  16. ADVANTAGES

  17. USAGE docker pull downloads an image docker run starts a

    container docker commit saves changes in an image docker push uploads an image
  18. DEMO

  19. LESSONS LEARNED AT SCHIBSTED

  20. ISSUE #1 ONE CONTAINER

  21. DOCKERFILE ### Install Supervisor RUN apt-get install -y supervisor &&

    mkdir -p /var/log/ supervisor ADD docker/supervisord.conf /etc/supervisor/conf.d/ supervisord.conf ### Install SSH, MongoDB, PHP, Apache2, composer ### (...) CMD supervisord -c /etc/supervisor/conf.d/ supervisord.conf
  22. SUPERVISORD.CONF [supervisord] nodaemon=true logfile=/var/www/phpers/app/logs/supervisord.log loglevel=debug [program:sshd] command=/usr/sbin/sshd -D [program:mongod] command=/usr/bin/mongod

    --smallfiles autorestart=true [program:apache2] command=/bin/bash -c "source /etc/apache2/envvars && exec /usr/sbin/apache2ctl -DFOREGROUND"
  23. ISSUE #2 WORKING ON MAC

  24. VAGRANT + DOCKER Host (MacOS) Vagrant Proxy VM (Ubuntu) Docker

    Container Supervisor Apache MongoDB
  25. VAGRANTFILE VAGRANTFILE_API_VERSION = "2" Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| config.ssh.username="root" config.vm.provider "docker"

    do |d| d.name = "phpers" d.build_dir = "." d.ports = ["80:80", "27017:27017"] d.volumes = [ "/vagrant/:/var/www/phpers:rw", "/data/db/:/data/db:rw" ] d.vagrant_vagrantfile = "proxy/Vagrantfile.proxy" end end
  26. VAGRANTFILE.PROXY VAGRANTFILE_API_VERSION = "2" Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| config.vm.box = "ubuntu/trusty64"

    config.vm.provision "docker" config.vm.provision "shell", inline: "ps aux | grep 'sshd:' | awk '{print $2}' | xargs kill" config.vm.network "private_network", ip: "192.168.33.12" config.vm.network "forwarded_port", guest: 80, host: 80 config.vm.network "forwarded_port", guest: 27017, host: 27017 config.vm.synced_folder "./../", "/vagrant", type: "nfs" config.vm.provider "virtualbox" do |v| v.name = "PHPers" v.memory = 2048 end end
  27. +

  28. ISSUE #3 THE PROCESS

  29. DEVELOPERS SITE sources with dockerfile Developer GitHub build image run

    image
  30. REMOTE SITE sources dockerfile image image sources image GitHub CircleCI

    AWS Docker Hub build image build with run with run with fire!
  31. REMOTE SITE sources dockerfile image image with sources image GitHub

    CircleCI AWS Docker Hub build build image with sources run image with sources run with fire!
  32. REMOTE SITE sources dockerfile image image sources image with sources

    GitHub CircleCI AWS Docker Hub build build with run with run image with sources fire!
  33. REMOTE SITE sources dockerfile image image with sources image with

    sources GitHub CircleCI AWS Docker Hub build image build image with sources run image with sources run image with sources fire!
  34. SHOULD YOU TRY DOCKER?

  35. REPOS https://github.com/sskorc/docker-silex https://github.com/sskorc/docker-symfony https://registry.hub.docker.com/u/sskorc/silex

  36. THAT’S ALL, THANKS! @sskorc