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. Dockerizing Development
    Eric Mann - Tozny

    View Slide

  2. –Jeremy Felt
    WordPress, meet Vagrant

    View Slide

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

    View Slide

  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!

    View Slide

  5. Is it good enough?

    View Slide

  6. The Production Problem
    How are new servers spun up?
    How does new code get to the server?
    What happens when things go wrong?

    View Slide

  7. View Slide

  8. View Slide

  9. Docker
    Build applications inside lightweight, distributable containers
    Isolate key infrastructure components:
    Web server
    Application
    Database
    Easily distribute development environments to the team

    View Slide

  10. View Slide

  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

    View Slide

  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

    View Slide

  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

    View Slide

  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

    View Slide

  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

    View Slide

  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

    View Slide

  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

    View Slide

  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

    View Slide

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

    View Slide

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

    upstream php53 {
    server localhost:9053;
    }

    View Slide

  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;
    ...
    }

    View Slide

  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;
    ...
    }

    View Slide

  23. Cool! But why?

    View Slide

  24. Docker - Advantages
    Build applications inside lightweight, distributable containers
    Isolate key infrastructure components:
    Web server
    Application
    Database
    Easily distribute development environments to the team

    View Slide

  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

    View Slide

  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

    View Slide

  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

    View Slide

  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

    View Slide

  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

    View Slide

  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”

    View Slide

  31. View Slide

  32. Source: rancher.com

    View Slide

  33. Questions?

    View Slide

  34. Dockerizing Development
    Eric Mann - Tozny

    View Slide