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

Dockerizing Development

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!

Eric Mann

August 04, 2016
Tweet

More Decks by Eric Mann

Other Decks in Programming

Transcript

  1. 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!
  2. The Production Problem How are new servers spun up? How

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

    components: Web server Application Database Easily distribute development environments to the team
  4. 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
  5. 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
  6. 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
  7. 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
  8. 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
  9. 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
  10. 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
  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. Map Application Ports upstream php { server localhost:9000; } 


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

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

    /index.php?$args; fastcgi_param ... # Use the upstream for php5-fpm fastcgi_pass php56; ... }
  15. Docker - Advantages Build applications inside lightweight, distributable containers Isolate

    key infrastructure components: Web server Application Database Easily distribute development environments to the team
  16. 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
  17. 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
  18. 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
  19. 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
  20. 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
  21. 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”