Kickass Development Environments with Docker (LeedsPHP, January, 2017)

Kickass Development Environments with Docker (LeedsPHP, January, 2017)

Docker, the hottest technology around at the moment. It swept the Ops world by storm in 2014, became mainstream in 2015, and now it’s set to dominate the developer world, in 2016.

Docker is a tool that allows you to package your application up into a single-runnable distributable binary - akin to the phar, but in Hulk mode. Docker allows you, a developer, to specify the exact environment your application needs to run, across development; test; staging; and production.

In this talk I will cover the creation of this utopian distributable and show you how to can compose your entire production infrastructure locally with only a small YAML file and without installing a single thing.

Lets say hello, to Docker.

69172dc4e4cc3e4cdd234c40adf395fa?s=128

David McKay

January 19, 2017
Tweet

Transcript

  1. 2.

    david@rawkode.com @rawkode github.com/rawkode ~ Organiser: ScotlandPHP Docker | DevOps MongoDb

    | Pair Programming Glasgow • PHP / Go / Elixir • DevOps / CI / CD / Docker • CQRS & Event Sourcing • Domain-Driven Design • TDD / BDD
  2. 5.

    Development Environments circa 2000 $ tree awesome-million-pound-project └── src ├──

    game.php ├── game.php.bk-david ├── game.php.bk-deano ├── main.php ├── main.php.maybe-fixed ├── main.php.bk-1999-12-02 ├── main.php.bk-1999-12-02.2 ├── player.php ├── player.php.orig └── .swp.player.php
  3. 6.

    Production Environments circa 2000 $ tree awesome-million-pound-project └── src ├──

    game.php ├── game.php.bk-david ├── game.php.bk-deano ├── main.php ├── main.php.maybe-fixed ├── main.php.bk-1999-12-02 ├── main.php.bk-1999-12-02.2 ├── player.php ├── player.php.orig └── .swp.player.php
  4. 9.
  5. 11.
  6. 12.
  7. 13.
  8. 14.

    Vagrant Problems • You’re creating and managing VMs for each

    project / service • Those VM’s are mutable / prone to error by user changes • They’re built JIT (most cases) • How long goes your vagrant up take?
  9. 17.

    What is Docker? Docker allows you to package an application

    with all of its dependencies into a standardized unit for software development. docker.com
  10. 19.

    The Docker Family • Docker • Docker Engine • Docker

    Registry • Docker Compose • Docker Machine • Docker Swarm
  11. 27.
  12. 38.
  13. 48.

    Configuring Services: Publishing Ports services: php: image: php:7-cli ports: -

    80 # Published on host as random natural number, from 32768
  14. 49.

    Configuring Services: Environment / 12-Factor services: mysql: image: mysql:8 environment:

    - MYSQL_DATABASE - MYSQL_USER=application - MYSQL_PASSWORD=password - MYSQL_RANDOM_ROOT_PASSWORD=true
  15. 50.

    Configuring Services: Environment / 12-Factor services: mysql: image: mysql:8 environment:

    MYSQL_DATABASE MYSQL_USER: application MYSQL_PASSWORD: password MYSQL_RANDOM_ROOT_PASSWORD: ’true’
  16. 62.

    docker-compose down -v • Stops and removes all containers and

    networks in the project • -v means delete the volumes as well Down Means Destroy
  17. 63.

    List all the Docker networks: docker network ls Feeling brave?

    docker network rm -f \ $(docker network ls -q) Mind Your Networks Avoid subnet collisions!
  18. 65.

    Base Image ONBUILD FTW # Dockerfile ONBUILD COPY . /var/www

    # docker-compose.yml application: image: my-base-image volumes: - .:/var/www # CI build FROM base-image
  19. 66.

    Base Image NIGHTLY BUILDS cron / curl / wget /

    whatever! There’s no cascading builds in Docker. Automate it
  20. 68.

    Single Process per Container Keep Attack Surface Small This will

    bode well from development to production!
  21. 75.
  22. 82.
  23. 84.