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

Kickass Development Environments with Docker (PHPBenelux 2019)

Kickass Development Environments with Docker (PHPBenelux 2019)

69172dc4e4cc3e4cdd234c40adf395fa?s=128

David McKay

January 26, 2019
Tweet

Transcript

  1. Hi #phpbnl19

  2. Kickass Development Environments with Docker

  3. @rawkode David McKay ◍ Developer Advocate at InfluxData ◍ Docker

    / CI / CD ◍ DevOps / SaltStack ◍ Event-Driven Systems ◍ CQRS / ES ◍ Elixir, Go, and Rust
  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 ◍ Virtualisation ◍ Image Delivery ◍

    Orchestration (Dev) ➔ docker build ➔ docker run ➔ docker push / pull ➔ docker-compose
  18. Image Building Introducing the Dockerfile

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

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

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

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

    php-cli COPY hello.php /code WORKDIR /code ENTRYPOINT [“php”] CMD [“-v”]
  23. (Simplified) Dockerfile for PHP FROM ubuntu:17.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 ◍ Virtualisation ◍ Image Delivery ◍

    Orchestration (Dev) ➔ docker build ➔ docker run ➔ docker push / pull ➔ docker-compose
  33. Virtualisation Running Docker Images as Containers

  34. Demo

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

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

  37. Your Super Application

  38. Your Super Application

  39. Docker Compose

  40. docker-compose.yml version: “3”

  41. docker-compose.yml version: “3” services: php: image: php:7 ports: - 80:80

    volumes: - .:/code
  42. docker-compose.yml version: “3” services: php: image: php:7 … database: image:

    mariadb:latest environment: MYSQL_USERNAME: rawkode MYSQL_PASSWORD: *******
  43. docker-compose.yml version: “3” services: php: image: php:7 … database: image:

    mariadb:latest environment: MYSQL_USERNAME: rawkode MYSQL_PASSWORD: *******
  44. docker-compose.yml version: “3” services: php: image: php:7 healthcheck: test: nc

    -z localhost 80 depends_on: - database
  45. Demo

  46. Docker ◍ Image Builder ◍ Virtualisation ◍ Image Delivery ◍

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

    to
  48. Tips: Use Random Ports services: php: ports: - 80

  49. 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
  50. Tips: Prune docker system prune Docker CE >= 17.04

  51. Tips: env_file Lots of environment variables defined inside compose.yml? Duplication?

    env_file: - some file
  52. Tips: Alpine Linux Unless you need Ubuntu / Fedora, use

    Alpine Linux Ubuntu -- 130MB Alpine -- 3.99MB
  53. Tips: Keep a Single Dockerfile Using MultiStage Builds, you can

    usually keep your project to a single Dockerfile FROM node AS node RUN npm install FROM php COPY --from=node assets
  54. Tips: Don’t Bust Your Build Cache COPY composer.json /code RUN

    composer install COPY . /code
  55. Tips: Logging ALWAYS LOG to STDOUT

  56. Production Tip Mandatory Requirement --read-only

  57. Warning Microservices

  58. “ That which is old will be new again

  59. Microservices

  60. Microservices

  61. Microservices

  62. Microservices

  63. Microservices

  64. What is old will be new again Shared Kubernetes Dev

    Server
  65. Microservices

  66. Shared Kubernetes Dev Server Tooling Skaffold github.com/GoogleContainerTools/skaffold Draft github.com/Azure/draft Telepresence

    github.com/telepresenceio/telepresence
  67. Shared Kubernetes Dev Server Tooling Istio github.com/istio/istio Linkerd linkerd/linkerd2 Consul

    Connect github.com/hashicorp/consul
  68. Creating a fast Kubernetes Development Workflow Bastian Hofmann / 1140

    / Track B
  69. Questions?