Slide 1

Slide 1 text

A presentation by @stuherbert
 for @GanbaroDigital Docker For Dev Envs Containers For PHP App Development

Slide 2

Slide 2 text

@GanbaroDigital Why?

Slide 3

Slide 3 text

@GanbaroDigital PHP Dev Env Blueprint

Slide 4

Slide 4 text

@GanbaroDigital vs

Slide 5

Slide 5 text

@GanbaroDigital I’m sharing my experience using VMs and then containers over the last 15+ years.

Slide 6

Slide 6 text

@GanbaroDigital Your experience may be different.

Slide 7

Slide 7 text

@GanbaroDigital I am here to learn from you too!

Slide 8

Slide 8 text

@GanbaroDigital Please Do Ask Questions!

Slide 9

Slide 9 text

@GanbaroDigital Why?

Slide 10

Slide 10 text

@GanbaroDigital ?? ?? Who Currently Uses Virtual Machines For Dev Environments?

Slide 11

Slide 11 text

@GanbaroDigital This has been a long journey for me.

Slide 12

Slide 12 text

@GanbaroDigital 1999/2000 VMWare Workstation

Slide 13

Slide 13 text

@GanbaroDigital 1999/2000 2008 VMWare Workstation VMWare ESX

Slide 14

Slide 14 text

@GanbaroDigital 1999/2000 2008 2010 VMWare Workstation VMWare ESX Linux KVM

Slide 15

Slide 15 text

@GanbaroDigital 1999/2000 2008 2010 2012 VMWare Workstation VMWare ESX Linux KVM VirtualBox & Vagrant

Slide 16

Slide 16 text

@GanbaroDigital 1999/2000 2008 2010 2012 2015 VMWare Workstation VMWare ESX Linux KVM VirtualBox & Vagrant Docker Containers

Slide 17

Slide 17 text

@GanbaroDigital 2018

Slide 18

Slide 18 text

@GanbaroDigital A search for improved stability, performance, and scalability.

Slide 19

Slide 19 text

@GanbaroDigital ?? ?? Why Do We Use Virtual Machines For Dev Environments?

Slide 20

Slide 20 text

@GanbaroDigital $

Slide 21

Slide 21 text

@GanbaroDigital http://localhost:8080/route/to/page?… $

Slide 22

Slide 22 text

@GanbaroDigital The web changed everything.

Slide 23

Slide 23 text

@GanbaroDigital We went from maintaining software to creating software.

Slide 24

Slide 24 text

@GanbaroDigital We went from developers per project to projects per developer.

Slide 25

Slide 25 text

@GanbaroDigital

Slide 26

Slide 26 text

@GanbaroDigital http://172.16.0.2/route/to/page?… $ Virtual Machine

Slide 27

Slide 27 text

@GanbaroDigital

Slide 28

Slide 28 text

@GanbaroDigital http://localhost/route/to/page?… $ Virtual Machine

Slide 29

Slide 29 text

@GanbaroDigital

Slide 30

Slide 30 text

@GanbaroDigital

Slide 31

Slide 31 text

@GanbaroDigital http://172.16.0.2/route/to/page?… $ Virtual Machine

Slide 32

Slide 32 text

@GanbaroDigital http://172.16.0.2/route/to/page?… $ Virtual Machine Virtual Machine Virtual Machine Virtual Machine

Slide 33

Slide 33 text

@GanbaroDigital

Slide 34

Slide 34 text

@GanbaroDigital

Slide 35

Slide 35 text

@GanbaroDigital http://172.16.0.2/route/to/page?… $ Virtual Machine Virtual Machine Virtual Machine Virtual Machine

Slide 36

Slide 36 text

@GanbaroDigital http://172.16.0.2/route/to/page?… $ Container Container Container Container

Slide 37

Slide 37 text

@GanbaroDigital Containers Are Lightweight At Runtime

Slide 38

Slide 38 text

@GanbaroDigital Containers Scale Better Than VMs

Slide 39

Slide 39 text

@GanbaroDigital Containers Are Fast* * on Linux!

Slide 40

Slide 40 text

@GanbaroDigital Containers Are Much Easier To Build

Slide 41

Slide 41 text

@GanbaroDigital

Slide 42

Slide 42 text

@GanbaroDigital “ Container Images Are A Unit of Delivery

Slide 43

Slide 43 text

@GanbaroDigital After two years of doing all my dev work in containers … … I’m never going back to developing in VMs.

Slide 44

Slide 44 text

@GanbaroDigital PHP Dev Env Blueprint

Slide 45

Slide 45 text

@GanbaroDigital

Slide 46

Slide 46 text

@GanbaroDigital

Slide 47

Slide 47 text

@GanbaroDigital Docker Compose (has no logo - sorry) (ships with Docker for Mac) (separate download on Linux)

Slide 48

Slide 48 text

@GanbaroDigital $ docker network create

Slide 49

Slide 49 text

@GanbaroDigital dnsmasq

Slide 50

Slide 50 text

@GanbaroDigital

Slide 51

Slide 51 text

@GanbaroDigital https://hub.docker.com/r/ganbarodigital/

Slide 52

Slide 52 text

@GanbaroDigital

Slide 53

Slide 53 text

@GanbaroDigital Steps 1. Create a network for our dev env 2. Define our dev env 3. Get DNS working for our dev env 4. Add a database server 5. Add our app

Slide 54

Slide 54 text

@GanbaroDigital Step 1

Slide 55

Slide 55 text

@GanbaroDigital Steps 1. Create a network for our dev env 2. Define our dev env 3. Get DNS working for our dev env 4. Add a database server 5. Add our app

Slide 56

Slide 56 text

@GanbaroDigital

Slide 57

Slide 57 text

@GanbaroDigital

Slide 58

Slide 58 text

@GanbaroDigital $ docker network create 
 --subnet 172.19.0.0/24 appdev

Slide 59

Slide 59 text

@GanbaroDigital $ docker network create 
 --subnet 172.19.0.0/24 appdev

Slide 60

Slide 60 text

@GanbaroDigital $ docker network create 
 --subnet 172.19.0.0/24 appdev

Slide 61

Slide 61 text

@GanbaroDigital $ docker network create 
 --subnet 172.19.0.0/24 appdev

Slide 62

Slide 62 text

@GanbaroDigital 172.19.0.0/24

Slide 63

Slide 63 text

@GanbaroDigital Step 2

Slide 64

Slide 64 text

@GanbaroDigital Steps 1. Create a network for our dev env 2. Define our dev env 3. Get DNS working for our dev env 4. Add a database server 5. Add our app

Slide 65

Slide 65 text

@GanbaroDigital 172.19.0.0/24

Slide 66

Slide 66 text

@GanbaroDigital myapp my-project

Slide 67

Slide 67 text

@GanbaroDigital docker-appenv myapp my-project

Slide 68

Slide 68 text

@GanbaroDigital docker-compose.yaml docker-appenv myapp my-project

Slide 69

Slide 69 text

@GanbaroDigital

Slide 70

Slide 70 text

@GanbaroDigital docker-appenv myapp my-project

Slide 71

Slide 71 text

@GanbaroDigital docker-appenv myapp my-project

Slide 72

Slide 72 text

@GanbaroDigital docker-appenv network-lead config data logs

Slide 73

Slide 73 text

@GanbaroDigital

Slide 74

Slide 74 text

@GanbaroDigital $ docker-compose start network-lead

Slide 75

Slide 75 text

@GanbaroDigital

Slide 76

Slide 76 text

@GanbaroDigital network-lead 172.19.0.2 172.19.0.0/24

Slide 77

Slide 77 text

@GanbaroDigital $ ping 172.19.0.2

Slide 78

Slide 78 text

@GanbaroDigital Step 3

Slide 79

Slide 79 text

@GanbaroDigital Steps 1. Create a network for our dev env 2. Define our dev env 3. Get DNS working for our dev env 4. Add a database server 5. Add our app

Slide 80

Slide 80 text

@GanbaroDigital network-lead 172.19.0.2 172.19.0.0/24

Slide 81

Slide 81 text

@GanbaroDigital $ ping 172.19.0.2

Slide 82

Slide 82 text

@GanbaroDigital $ ping network-lead.appdev

Slide 83

Slide 83 text

@GanbaroDigital dnsmasq

Slide 84

Slide 84 text

@GanbaroDigital Multi-Resolver O/S Support 1. Ubuntu 16.04 - supported by default 2. Ubuntu 17.04 - install & config required 3. MacOS - supported by default

Slide 85

Slide 85 text

@GanbaroDigital /etc/NetworkManager/dnsmasq.d/ appdev.conf (on Ubuntu)

Slide 86

Slide 86 text

@GanbaroDigital server=/appdev/172.19.0.2

Slide 87

Slide 87 text

@GanbaroDigital server=/appdev/172.19.0.2

Slide 88

Slide 88 text

@GanbaroDigital server=/appdev/172.19.0.2

Slide 89

Slide 89 text

@GanbaroDigital network-lead 172.19.0.2 172.19.0.0/24

Slide 90

Slide 90 text

@GanbaroDigital Reboot to make sure new config is picked up.

Slide 91

Slide 91 text

@GanbaroDigital /etc/resolver/appdev (on MacOS)

Slide 92

Slide 92 text

@GanbaroDigital /etc/resolver/appdev (on MacOS)

Slide 93

Slide 93 text

@GanbaroDigital nameserver 172.19.0.2

Slide 94

Slide 94 text

@GanbaroDigital network-lead 172.19.0.2 172.19.0.0/24

Slide 95

Slide 95 text

@GanbaroDigital Out of the box, Docker for Mac needs an extra step. I’ll cover that separately at the end.

Slide 96

Slide 96 text

@GanbaroDigital $ ping network-lead.appdev

Slide 97

Slide 97 text

@GanbaroDigital

Slide 98

Slide 98 text

@GanbaroDigital Setting up DNS is a one-off task per Docker network

Slide 99

Slide 99 text

@GanbaroDigital Step 4

Slide 100

Slide 100 text

@GanbaroDigital Steps 1. Create a network for our dev env 2. Define our dev env 3. Get DNS working for our dev env 4. Add a database server 5. Add our app

Slide 101

Slide 101 text

@GanbaroDigital The hard work is done :)

Slide 102

Slide 102 text

@GanbaroDigital

Slide 103

Slide 103 text

@GanbaroDigital docker-appenv network-lead config data logs

Slide 104

Slide 104 text

@GanbaroDigital docker-appenv mysql config data logs

Slide 105

Slide 105 text

@GanbaroDigital

Slide 106

Slide 106 text

@GanbaroDigital Acid test for container design #1 Will you lose anything if you destroy the container?

Slide 107

Slide 107 text

@GanbaroDigital I’ll tackle container image design in a separate talk.

Slide 108

Slide 108 text

@GanbaroDigital $ docker-compose start mysql

Slide 109

Slide 109 text

@GanbaroDigital network-lead mysql 172.19.0.2 172.19.0.3 172.19.0.0/24

Slide 110

Slide 110 text

@GanbaroDigital

Slide 111

Slide 111 text

@GanbaroDigital $ mysql -h mysql.appdev -u root -p

Slide 112

Slide 112 text

@GanbaroDigital You can use MySQL Workbench from the host OS too. Or any other tools. It’s just MySQL after all.

Slide 113

Slide 113 text

@GanbaroDigital Step 5

Slide 114

Slide 114 text

@GanbaroDigital Steps 1. Create a network for our dev env 2. Define our dev env 3. Get DNS working for our dev env 4. Add a database server 5. Add our app

Slide 115

Slide 115 text

@GanbaroDigital

Slide 116

Slide 116 text

@GanbaroDigital

Slide 117

Slide 117 text

@GanbaroDigital docker-appenv myapp my-project

Slide 118

Slide 118 text

@GanbaroDigital docker-appenv myapp my-project

Slide 119

Slide 119 text

@GanbaroDigital

Slide 120

Slide 120 text

@GanbaroDigital

Slide 121

Slide 121 text

@GanbaroDigital $ docker-compose start myapp

Slide 122

Slide 122 text

@GanbaroDigital

Slide 123

Slide 123 text

@GanbaroDigital network-lead mysql myapp wordpress 172.19.0.2 172.19.0.3 172.19.0.4 172.19.0.5 172.19.0.0/24

Slide 124

Slide 124 text

@GanbaroDigital PDO: mysql:host=mysql;charset=UTF8

Slide 125

Slide 125 text

@GanbaroDigital

Slide 126

Slide 126 text

@GanbaroDigital vs

Slide 127

Slide 127 text

@GanbaroDigital The differences are important to PHP developers.

Slide 128

Slide 128 text

@GanbaroDigital

Slide 129

Slide 129 text

@GanbaroDigital

Slide 130

Slide 130 text

@GanbaroDigital

Slide 131

Slide 131 text

@GanbaroDigital There *is* a workaround (of sorts) https://github.com/docker/for-mac/issues/ 155#issuecomment-320509769

Slide 132

Slide 132 text

@GanbaroDigital Maxed-out 2016 MacBook Pro vs an UltraBook running Linux

Slide 133

Slide 133 text

@GanbaroDigital It’s hardly a fair fight.

Slide 134

Slide 134 text

@GanbaroDigital A B 0 32 64 96 128 160

Slide 135

Slide 135 text

@GanbaroDigital Linux MacOS 0 32 64 96 128 160

Slide 136

Slide 136 text

@GanbaroDigital Docker for Mac has performance bottlenecks compared to Docker on Linux

Slide 137

Slide 137 text

@GanbaroDigital

Slide 138

Slide 138 text

@GanbaroDigital

Slide 139

Slide 139 text

@GanbaroDigital Containers Are A Linux-Native Technology

Slide 140

Slide 140 text

@GanbaroDigital Containers Are Not Native To MacOS

Slide 141

Slide 141 text

@GanbaroDigital On MacOS containers run in a virtual machine

Slide 142

Slide 142 text

@GanbaroDigital On MacOS Docker isn’t a seamless experience (yet)

Slide 143

Slide 143 text

@GanbaroDigital I switched to Linux for all my dev work. Because that’s where the best Docker experience is.

Slide 144

Slide 144 text

Thank You Any Questions? A presentation by @stuherbert
 for @GanbaroDigital

Slide 145

Slide 145 text

@GanbaroDigital Image Credits 1. Docker Logo:
 https://www.docker.com/brand-guidelines 2. Brigadier Mk3: https://flic.kr/p/jB4t16 3. Container Wall: https://flic.kr/p/fMsCgA 4. Container Ship: https://flic.kr/p/SGHmdX

Slide 146

Slide 146 text

@GanbaroDigital Image Credits 1. Brick Wall: https://flic.kr/p/wCRJZ4 2. Single Tortoise: https://flic.kr/p/wBEFaf 3. Multiple Tortoises: https://flic.kr/p/RxXZag 4. Isolation: https://flic.kr/p/pQnn9e

Slide 147

Slide 147 text

@GanbaroDigital Image Credits 1. Data Center: https://flic.kr/p/4Fnm8M