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 full-size slide

  2. –Jeremy Felt
    WordPress, meet Vagrant

    View full-size slide

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

    View full-size 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 full-size slide

  5. Is it good enough?

    View full-size 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 full-size slide

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

    View full-size slide

  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

    View full-size slide

  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

    View full-size slide

  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

    View full-size 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 full-size 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 full-size 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 full-size 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 full-size 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 full-size slide

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

    View full-size slide

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

    upstream php53 {
    server localhost:9053;
    }

    View full-size slide

  18. 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 full-size slide

  19. 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 full-size slide

  20. Cool! But why?

    View full-size slide

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

    View full-size slide

  22. 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 full-size slide

  23. 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 full-size slide

  24. 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 full-size slide

  25. 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 full-size slide

  26. 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 full-size slide

  27. 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 full-size slide

  28. Source: rancher.com

    View full-size slide

  29. Dockerizing Development
    Eric Mann - Tozny

    View full-size slide