Dockerizing Development

46093583d8895095adb1b0071c505af2?s=47 Eric Mann
August 04, 2016

Dockerizing Development

Our development team uses Vagrant-powered virtual machines for local development, a multi-tenant staging environment for client demos, and manages multiple production servers for client websites. Until recently, every system in that fragile chain was running a different version of PHP.

And by “fragile chain” I mean this system caused headaches for the team. Every. Single. Day.

To resolve the problem, I’ve introduced the team to Docker, using containers to wrap every version of PHP we use and host all of them on the same machine at the same time. Our local Vagrant environments still allow us to code locally, but we can dynamically select the version of PHP we’re coding against with a cookie. The multi-tenant staging environment still works, but every staging instance can target a specific version of PHP.

Finally, we can use the same version of PHP at every level of the chain and never see another syntax error because an engineer developing locally against PHP 5.6 pushed code to a server running PHP 5.3. Want to see how I set this up for my team? Great! Everyone is open source and I’ll walk you through every step – then you can help Dockerize your team’s development environments, too!

46093583d8895095adb1b0071c505af2?s=128

Eric Mann

August 04, 2016
Tweet

Transcript

  1. Dockerizing Development Eric Mann - Tozny

  2. –Jeremy Felt WordPress, meet Vagrant

  3. Varying Vagrant Vagrants What’s even better: it’s disposable!

  4. Evolution Bundles the WordPress development suite Keeps up-to-date with PHP

    and MySQL changes Empowers simple, local development complete with unit testing, runtime debugging, and even production-style caching Continues to evolve with contributions!
  5. Is it good enough?

  6. The Production Problem How are new servers spun up? How

    does new code get to the server? What happens when things go wrong?
  7. None
  8. None
  9. Docker Build applications inside lightweight, distributable containers Isolate key infrastructure

    components: Web server Application Database Easily distribute development environments to the team
  10. None
  11. Parallel PHP Versions docker run -d --restart=always --net=host -v /srv/www:/srv/www

    10up/php:5.3-fpm docker run -d --restart=always --net=host -v /srv/www:/srv/www 10up/php:5.4-fpm docker run -d --restart=always --net=host -v /srv/www:/srv/www 10up/php:5.5-fpm docker run -d --restart=always --net=host -v /srv/www:/srv/www 10up/php:5.6-fpm docker run -d --restart=always --net=host -v /srv/www:/srv/www 10up/php:7.0-fpm
  12. Parallel PHP Versions docker run -d --restart=always --net=host -v /srv/www:/srv/www

    10up/php:5.3-fpm docker run -d --restart=always --net=host -v /srv/www:/srv/www 10up/php:5.4-fpm docker run -d --restart=always --net=host -v /srv/www:/srv/www 10up/php:5.5-fpm docker run -d --restart=always --net=host -v /srv/www:/srv/www 10up/php:5.6-fpm docker run -d --restart=always --net=host -v /srv/www:/srv/www 10up/php:7.0-fpm
  13. Parallel PHP Versions docker run -d --restart=always --net=host -v /srv/www:/srv/www

    10up/php:5.3-fpm docker run -d --restart=always --net=host -v /srv/www:/srv/www 10up/php:5.4-fpm docker run -d --restart=always --net=host -v /srv/www:/srv/www 10up/php:5.5-fpm docker run -d --restart=always --net=host -v /srv/www:/srv/www 10up/php:5.6-fpm docker run -d --restart=always --net=host -v /srv/www:/srv/www 10up/php:7.0-fpm
  14. Parallel PHP Versions docker run -d --restart=always --net=host -v /srv/www:/srv/www

    10up/php:5.3-fpm docker run -d --restart=always --net=host -v /srv/www:/srv/www 10up/php:5.4-fpm docker run -d --restart=always --net=host -v /srv/www:/srv/www 10up/php:5.5-fpm docker run -d --restart=always --net=host -v /srv/www:/srv/www 10up/php:5.6-fpm docker run -d --restart=always --net=host -v /srv/www:/srv/www 10up/php:7.0-fpm
  15. Parallel PHP Versions docker run -d --restart=always --net=host -v /srv/www:/srv/www

    10up/php:5.3-fpm docker run -d --restart=always --net=host -v /srv/www:/srv/www 10up/php:5.4-fpm docker run -d --restart=always --net=host -v /srv/www:/srv/www 10up/php:5.5-fpm docker run -d --restart=always --net=host -v /srv/www:/srv/www 10up/php:5.6-fpm docker run -d --restart=always --net=host -v /srv/www:/srv/www 10up/php:7.0-fpm
  16. Parallel PHP Versions docker run -d --restart=always --net=host -v /srv/www:/srv/www

    10up/php:5.3-fpm docker run -d --restart=always --net=host -v /srv/www:/srv/www 10up/php:5.4-fpm docker run -d --restart=always --net=host -v /srv/www:/srv/www 10up/php:5.5-fpm docker run -d --restart=always --net=host -v /srv/www:/srv/www 10up/php:5.6-fpm docker run -d --restart=always --net=host -v /srv/www:/srv/www 10up/php:7.0-fpm
  17. Parallel PHP Versions docker run -d --restart=always --net=host -v /srv/www:/srv/www

    10up/php:5.3-fpm docker run -d --restart=always --net=host -v /srv/www:/srv/www 10up/php:5.4-fpm docker run -d --restart=always --net=host -v /srv/www:/srv/www 10up/php:5.5-fpm docker run -d --restart=always --net=host -v /srv/www:/srv/www 10up/php:5.6-fpm docker run -d --restart=always --net=host -v /srv/www:/srv/www 10up/php:7.0-fpm
  18. Parallel PHP Versions docker run -d --restart=always --net=host -v /srv/www:/srv/www

    10up/php:5.3-fpm docker run -d --restart=always --net=host -v /srv/www:/srv/www 10up/php:5.4-fpm docker run -d --restart=always --net=host -v /srv/www:/srv/www 10up/php:5.5-fpm docker run -d --restart=always --net=host -v /srv/www:/srv/www 10up/php:5.6-fpm docker run -d --restart=always --net=host -v /srv/www:/srv/www 10up/php:7.0-fpm
  19. Map Application Ports upstream php { server localhost:9000; } 


  20. Map Application Ports upstream php { server localhost:9000; } 


    upstream php53 { server localhost:9053; }
  21. Update Nginx location / { index index.php; try_files $uri $uri/

    /index.php?$args; fastcgi_param ... # Use the upstream for php5-fpm fastcgi_pass php; ... }
  22. Update Nginx location / { index index.php; try_files $uri $uri/

    /index.php?$args; fastcgi_param ... # Use the upstream for php5-fpm fastcgi_pass php56; ... }
  23. Cool! But why?

  24. Docker - Advantages Build applications inside lightweight, distributable containers Isolate

    key infrastructure components: Web server Application Database Easily distribute development environments to the team
  25. Docker - Advantages Keep your applications from colliding with one

    another Isolate key infrastructure components: Web server Application Database Easily distribute development environments to the team
  26. Docker - Advantages Keep your applications from colliding with one

    another Make everything a separate container: Web server Application Database Easily distribute development environments to the team
  27. Docker - Advantages Keep your applications from colliding with one

    another Make everything a separate container: Nginx + Varnish + Let’s Encrypt Application Database Easily distribute development environments to the team
  28. Docker - Advantages Keep your applications from colliding with one

    another Make everything a separate container: Nginx + Varnish + Let’s Encrypt PHP + WordPress/Drupal/Joomla/etc Database Easily distribute development environments to the team
  29. Docker - Advantages Keep your applications from colliding with one

    another Make everything a separate container: Nginx + Varnish + Let’s Encrypt PHP + WordPress/Drupal/Joomla/etc MySQL or Percona or Maria or RDS Easily distribute development environments to the team
  30. Docker - Advantages Keep your applications from colliding with one

    another Make everything a separate container: Nginx + Varnish + Let’s Encrypt PHP + WordPress/Drupal/Joomla/etc MySQL or Percona or Maria or RDS “Works on my machine” == “It works”
  31. None
  32. Source: rancher.com

  33. Questions?

  34. Dockerizing Development Eric Mann - Tozny