Slide 1

Slide 1 text

Hi #phpbnl19

Slide 2

Slide 2 text

Kickass Development Environments with Docker

Slide 3

Slide 3 text

@rawkode David McKay ◍ Developer Advocate at InfluxData ◍ Docker / CI / CD ◍ DevOps / SaltStack ◍ Event-Driven Systems ◍ CQRS / ES ◍ Elixir, Go, and Rust

Slide 4

Slide 4 text

Let us travel through time ...

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

Things eventually got better ...

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

Dev / Prod Parity

Slide 11

Slide 11 text

Eurgh, DSL Hell

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

Problems with Vagrant Slow to provision RAM intensive Really, development only Requires a CM tool

Slide 14

Slide 14 text

How long does your vagrant up take?

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

“ Docker allows you to package an application with all of its dependencies into a standardized unit for software development.

Slide 17

Slide 17 text

Docker ◍ Image Builder ◍ Virtualisation ◍ Image Delivery ◍ Orchestration (Dev) ➔ docker build ➔ docker run ➔ docker push / pull ➔ docker-compose

Slide 18

Slide 18 text

Image Building Introducing the Dockerfile

Slide 19

Slide 19 text

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

Slide 20

Slide 20 text

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

Slide 21

Slide 21 text

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

Slide 22

Slide 22 text

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

Slide 23

Slide 23 text

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

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

ENTRYPOINT & CMD Explained in 20 seconds

Slide 26

Slide 26 text

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

Slide 27

Slide 27 text

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

Slide 28

Slide 28 text

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

Slide 29

Slide 29 text

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

Slide 30

Slide 30 text

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

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

Docker ◍ Image Builder ◍ Virtualisation ◍ Image Delivery ◍ Orchestration (Dev) ➔ docker build ➔ docker run ➔ docker push / pull ➔ docker-compose

Slide 33

Slide 33 text

Virtualisation Running Docker Images as Containers

Slide 34

Slide 34 text

Demo

Slide 35

Slide 35 text

Docker ◍ Image Builder ◍ Virtualisation ◍ Image Delivery ◍ Orchestration (Dev) ➔ docker build ➔ docker run ➔ docker push / pull ➔ docker-compose

Slide 36

Slide 36 text

Orchestration (Dev) Composing Services

Slide 37

Slide 37 text

Your Super Application

Slide 38

Slide 38 text

Your Super Application

Slide 39

Slide 39 text

Docker Compose

Slide 40

Slide 40 text

docker-compose.yml version: “3”

Slide 41

Slide 41 text

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

Slide 42

Slide 42 text

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

Slide 43

Slide 43 text

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

Slide 44

Slide 44 text

docker-compose.yml version: “3” services: php: image: php:7 healthcheck: test: nc -z localhost 80 depends_on: - database

Slide 45

Slide 45 text

Demo

Slide 46

Slide 46 text

Docker ◍ Image Builder ◍ Virtualisation ◍ Image Delivery ◍ Orchestration (Dev) ➔ docker build ➔ docker run ➔ docker push / pull ➔ docker-compose

Slide 47

Slide 47 text

Tips I’ve learnt the hard way, so you don’t have to

Slide 48

Slide 48 text

Tips: Use Random Ports services: php: ports: - 80

Slide 49

Slide 49 text

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

Slide 50

Slide 50 text

Tips: Prune docker system prune Docker CE >= 17.04

Slide 51

Slide 51 text

Tips: env_file Lots of environment variables defined inside compose.yml? Duplication? env_file: - some file

Slide 52

Slide 52 text

Tips: Alpine Linux Unless you need Ubuntu / Fedora, use Alpine Linux Ubuntu -- 130MB Alpine -- 3.99MB

Slide 53

Slide 53 text

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

Slide 54

Slide 54 text

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

Slide 55

Slide 55 text

Tips: Logging ALWAYS LOG to STDOUT

Slide 56

Slide 56 text

Production Tip Mandatory Requirement --read-only

Slide 57

Slide 57 text

Warning Microservices

Slide 58

Slide 58 text

“ That which is old will be new again

Slide 59

Slide 59 text

Microservices

Slide 60

Slide 60 text

Microservices

Slide 61

Slide 61 text

Microservices

Slide 62

Slide 62 text

Microservices

Slide 63

Slide 63 text

Microservices

Slide 64

Slide 64 text

What is old will be new again Shared Kubernetes Dev Server

Slide 65

Slide 65 text

Microservices

Slide 66

Slide 66 text

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

Slide 67

Slide 67 text

Shared Kubernetes Dev Server Tooling Istio github.com/istio/istio Linkerd linkerd/linkerd2 Consul Connect github.com/hashicorp/consul

Slide 68

Slide 68 text

Creating a fast Kubernetes Development Workflow Bastian Hofmann / 1140 / Track B

Slide 69

Slide 69 text

Questions?