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

LaraconEU 2018 - Kickass Development Environments with Docker

LaraconEU 2018 - Kickass Development Environments with Docker

69172dc4e4cc3e4cdd234c40adf395fa?s=128

David McKay

August 30, 2018
Tweet

Transcript

  1. Hello, LaraconEU 2018

  2. @rawkode @david@rawkode.com Organiser of Things ◍ Cloud Native Glasgow ◍

    DevOps Glasgow ◍ MongoDB Glasgow ◍ PairProg Glasgow Software & Site Reliability ◍ Elixir / Rust / Go / Pony ◍ Docker / CI / CD ◍ DevOps / SaltStack ◍ Event-Driven Systems ◍ CQRS / ES
  3. Kickass Development Environments with Docker

  4. Let us travel through time ...

  5. My Development Environment 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
  6. My Development Production Environment 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
  7. Things eventually got better ...

  8. None
  9. None
  10. Dev / Prod Parity

  11. Eurgh, DSL Hell

  12. None
  13. Problems with Vagrant Slow to provision RAM intensive Really, development

    only Requires a CM tool
  14. How long does your vagrant up take?

  15. None
  16. “ Docker allows you to package an application with all

    of its dependencies into a standardized unit for software development.
  17. Docker ◍ Image Builder ◍ Image Delivery ◍ Virtualisation ◍

    Orchestration (Dev) ➢ docker image build ➢ docker image push/ll ➢ docker container run ➢ docker-compose Build. Ship. Run.
  18. Image Building Introducing the Dockerfile

  19. (Simplified) Dockerfile for PHP FROM ubuntu:18.04 RUN apt install -y

    php-cli COPY hello.php /code WORKDIR /code ENTRYPOINT [“php”] CMD [“-v”]
  20. (Simplified) Dockerfile for PHP FROM ubuntu:18.04 RUN apt install -y

    php-cli COPY hello.php /code WORKDIR /code ENTRYPOINT [“php”] CMD [“-v”]
  21. (Simplified) Dockerfile for PHP FROM ubuntu:18.04 RUN apt install -y

    php-cli COPY hello.php /code WORKDIR /code ENTRYPOINT [“php”] CMD [“-v”]
  22. (Simplified) Dockerfile for PHP FROM ubuntu:18.04 RUN apt install -y

    php-cli COPY hello.php /code WORKDIR /code # PLEASE DON’T DO RUN cd /code
  23. (Simplified) Dockerfile for PHP FROM ubuntu:18.04 RUN apt install -y

    php-cli COPY hello.php /code WORKDIR /code ENTRYPOINT [“php”] CMD [“-v”]
  24. None
  25. ENTRYPOINT & CMD Explained in 20 seconds

  26. ENTRYPOINT and CMD Explained in 17 seconds ... CMD [“echo”,

    “Hello”] in a Dockerfile docker run my-image == $ Hello
  27. ENTRYPOINT and CMD Explained in 13 seconds ... CMD [“echo”,

    “Hello”] in a Dockerfile docker run my-image echo Goodbye == $ Goodbye
  28. ENTRYPOINT and CMD Explained in 10 seconds ... ENTRYPOINT [“echo”]

    CMD [“Hello”] in a Dockerfile docker run my-image == $ Hello
  29. ENTRYPOINT and CMD Explained in 7 seconds ... ENTRYPOINT [“echo”]

    CMD [“Hello”] in a Dockerfile docker run --entrypoint=”echo” my-image Woop! == $ Woop!
  30. ENTRYPOINT and CMD Explained in 4 seconds ... ENTRYPOINT [“echo”]

    CMD [“Hello”] in a Dockerfile docker run --entrypoint=”echo” my-image == $
  31. None
  32. Docker ◍ Image Builder ◍ Image Delivery ◍ Virtualisation ◍

    Orchestration (Dev) ➔ docker image build ➔ docker image push/ll ➔ docker container run ➔ docker-compose
  33. Image Delivery & Virtualisation Running Docker Images as Containers

  34. Demo

  35. Docker ◍ Image Builder ◍ Image Delivery ◍ Virtualisation ◍

    Orchestration (Dev) ➔ docker build ➔ docker push / pull ➔ docker run ➔ docker-compose
  36. Orchestration (Dev) Composing Services

  37. Your Super Application

  38. Your Super Application

  39. Docker Compose

  40. Docker for Local Development 4 Easy Steps. I’ll discuss 3.

    1. Satisfy Dependencies 2. Introduce Docker for CI 3. Adopt Docker Shell Pattern 4. 12-Factor (Catch Alex’s talk on YouTube)
  41. Satisfy Dependencies PostgreSQL, Redis, Elasticsearch, et al.

  42. docker-compose.yml services: database: image: mariadb:10.1 environment: MYSQL_USER: rawkode MYSQL_PASSWORD: *******

    MYSQL_DATABASE: my-awesome-app
  43. docker-compose.yml version: “2.4”

  44. docker-compose.yml version: “2.4” services: php: image: php:7 ports: - 80:80

    volumes: - .:/code:cached tmpfs: - /code/var/logs - /code/var/cache
  45. docker-compose.yml version: “2.4” services: php: image: php:7 … database: image:

    mariadb:10.1 environment: MYSQL_USERNAME: rawkode MYSQL_PASSWORD: *******
  46. docker-compose.yml version: “2.4” services: php: image: php:7 healthcheck: test: nc

    -z localhost 80 depends_on: database: condition: service_healthy
  47. Introduce Docker to CI Craft Your Dockerfile

  48. Docker for CI ◍ Multi-Stage Builds ◍ Mind Your Build-Cache

    ◍ Be Wary of “Helper” Scripts ◍ We’ll cover these in the demo
  49. Docker Shell Maintain Native Workflows

  50. Docker Shell Pattern ◍ Your base container has all your

    system dependencies (Don’t use --ignore-platform-reqs) ◍ Work natively, but in the container ◍ You’ll still get all the perks
  51. Demo

  52. Docker ◍ Image Builder ◍ Virtualisation ◍ Image Delivery ◍

    Orchestration (Dev) ➔ docker build ➔ docker run ➔ docker push / pull ➔ docker-compose
  53. Tips I’ve learnt the hard way, so you don’t have

    to
  54. Zsh Plugin https://github.com /rawkode /zsh-docker-run

  55. Tips: Don’t Bust Your Build Cache COPY composer.json /code RUN

    composer install COPY . /code
  56. Tips: Mindful of Network Collisions Every new docker-compose file is,

    potentially, a new docker network / bridge on your host. Eventually, you’ll get a collision docker-compose down Add -v to remove volumes
  57. Tips: Logging ALWAYS LOG to STDOUT

  58. Tips: Prune docker system prune Docker CE >= 17.04

  59. Tips: Alpine Linux Unless you need Ubuntu / Fedora, use

    Alpine Linux Ubuntu -- 130MB / 85MB Alpine -- 3.99MB
  60. Production Tip nginx & fpm --volumes-from=php

  61. Production Tip Open Census Open Metrics Open Tracing

  62. Production Tip Mandatory Requirement --read-only

  63. Thank You! Questions? @david@rawkode.com @rawkode