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

Docker for Development

Docker for Development

Quick introduction to Docker and how it fits the modern development workflow, plus a few tips about running docker inside Vagrant and on the differences between docker run and docker exec.

I originally gave this talk internally at HelloFresh in March 2016, and later at the August meetup of Berlin PHP Usergroup.

Pedro Candeias

August 02, 2016
Tweet

Other Decks in Programming

Transcript

  1. Docker for Development Pedro Gil @pgcandeias Container Docks, 2/12 ©

    2012 Louis Vest - https://flic.kr/p/bSrWHc
  2. About me • Mostly into dynamic languages (php/js/python) • Head

    of Platform Engineering at HelloFresh • Migrating monoliths into microservices • Taking care of the services and tools used by our developers
  3. What’s Docker? “Docker containers wrap up a piece of software

    in a complete filesystem that contains everything it needs to run: code, runtime, system tools, system libraries – anything you can install on a server. This guarantees that it will always run the same, regardless of the environment it is running in.” https://www.docker.com/what-docker
  4. Containers • Similar to virtual machines • Don’t need a

    whole OS per container • Much smaller than VMs https://www.docker.com/what-docker
  5. Container benefits • Consume very little memory and disk •

    We can run lots and lots of them in a laptop • Spin up in under a second • Disposable Container © 2013 www.GlynLowe.com - https://flic.kr/p/hD7Jqz
  6. So basically… We can run very complex distributed systems with

    dozens of hosts We can closely simulate production topology In our laptops! © 2015 Dirk Dallas - https://flic.kr/p/qZbDqf
  7. What’s Docker? Docker is witchcraft. La Bruja del Mar ©

    2012 Sergio Otero - https://flic.kr/p/eFAV7T
  8. That’s nice, kid but what’s in it for me? ©

    Lucasfilm Ltd - http://www.starwars.com/databank/han-solo
  9. In the olden days… • We worked on bare metal

    • Language interpreters, databases and web servers all installed in our machines • Working with multiple versions of the same thing (language, database, etc) sucked • Environment management solutions emerged • Many differences between development and production. Ibiza Medieval 2011 © 2011 Juan Pacheco Tirado - https://flic.kr/p/9Fnrnp
  10. Enter Vagrant • Easy virtualization • Same environment in development

    and production • Different VMs for different projects, each with its own dependency versions • Easy to share https://commons.wikimedia.org/wiki/File:Vagrant.png
  11. Vagrant issues • Still a lot of overhead • No

    easy way to accurately represent large, diverse topologies • Untenable for large, distributed applications https://www.docker.com/what-docker
  12. Container benefits • Consume very little memory and disk •

    We can run lots and lots of them in a laptop • Spin up in under a second • Disposable https://www.docker.com/what-docker
  13. Docker requires Linux Other OSes, such as OS X or

    Windows, require using some sort of linux based virtual machine for Docker Engine to run. Docker machine (previously boot2docker) is basically just a linux VM with docker engine inside.
  14. Use docker machine. Problem? • Broken filesystem sync • Live

    code editing doesn’t work • No big deal for compiled languages, but it sucks for php, JS, python, etc • Accessing each app on a different port also sucks • So yes, Sherlock, problem. http://www.independent.co.uk/
  15. Vagrant to the rescue • Proper NFS shares allow code

    changes to propagate to containers • Multiple network interfaces allow multiple apps to run on port 80 (for example) • Really nice customisation all around • Still easy to share https://commons.wikimedia.org/wiki/File:Vagrant.png
  16. docker compose creating a nice application cluster with your code

    and all ancillary services like databases
  17. docker run -ti ubuntu bin/bash • Pulls the ubuntu image

    from a registry • Creates a new container • Allocates a filesystem and mounts a read-write layer • Allocates a network / bridge interface • Sets up an IP address • Executes a process that you specify (hello) • Captures and provides application output • Stops the container as soon as the command is done
  18. docker exec -ti ubuntu_1 bin/bash • Executes a comand in

    an already running container • In this case, executing bash means you get a shell • This is how you can see logs for an application server, for instance • Any changes made during this session persist in the running instance
  19. In summary • Docker allows developing on a topology that

    resembles production much more closely than bare metal or VMs • Doesn’t run on OS X but we can fix that using a vagrant box with docker-engine installed • docker-compose lets us define complex clusters easily for development • Containers are cheap. Kill them, restart them, change their versions easily.