Slide 1

Slide 1 text

DOCKERIZE YOUR DEVELOPMENT SETUP 1 — Srdjan Vranac, Code4Hire, PHPSrbija 2017

Slide 2

Slide 2 text

business owner, developer, consultant, mercenary, writing terrible code that performs exceptionally, wrangling elePHPants and Pythons, obsessed with process automation, interested in continuous integration and delivery, clean code, testing, best practices and distributed systems 2 — Srdjan Vranac, Code4Hire, PHPSrbija 2017

Slide 3

Slide 3 text

3 — Srdjan Vranac, Code4Hire, PHPSrbija 2017

Slide 4

Slide 4 text

4 — Srdjan Vranac, Code4Hire, PHPSrbija 2017

Slide 5

Slide 5 text

5 — Srdjan Vranac, Code4Hire, PHPSrbija 2017

Slide 6

Slide 6 text

6 — Srdjan Vranac, Code4Hire, PHPSrbija 2017

Slide 7

Slide 7 text

7 — Srdjan Vranac, Code4Hire, PHPSrbija 2017

Slide 8

Slide 8 text

8 — Srdjan Vranac, Code4Hire, PHPSrbija 2017

Slide 9

Slide 9 text

WHAT IS DOCKER? 9 — Srdjan Vranac, Code4Hire, PHPSrbija 2017

Slide 10

Slide 10 text

IMAGES 10 — Srdjan Vranac, Code4Hire, PHPSrbija 2017

Slide 11

Slide 11 text

CONTAINERS 11 — Srdjan Vranac, Code4Hire, PHPSrbija 2017

Slide 12

Slide 12 text

NETWORK $ docker network ls NETWORK ID NAME DRIVER 7fca4eb8c647 bridge bridge 9f904ee27bf5 none null cf03ee007fb4 host host 12 — Srdjan Vranac, Code4Hire, PHPSrbija 2017

Slide 13

Slide 13 text

VOLUMES 13 — Srdjan Vranac, Code4Hire, PHPSrbija 2017

Slide 14

Slide 14 text

DOCKERFILE 14 — Srdjan Vranac, Code4Hire, PHPSrbija 2017

Slide 15

Slide 15 text

FROM alpine:3.5 LABEL maintainer Srdjan Vranac ARG NGINX_PROJECT_ROOT="/application/web" ARG NGINX_ENTRY_POINT_FILE="app_dev.php" ARG NGINX_ALLOWED_FILES="app|app_dev|config" RUN apk add --update nginx && rm -rf /var/cache/apk/* ADD ./nginx.conf /etc/nginx/nginx.conf ADD ./application-7.1.conf \ ./application-debug-7.1.conf \ ./application-7.0.conf \ ./application-debug-7.0.conf \ ./application-5.6.conf \ ./application-debug-5.6.conf \ /etc/nginx/conf.d/ RUN /bin/sed -i "s@\${PROJECT_ROOT}@$NGINX_PROJECT_ROOT@" /etc/nginx/conf.d/application*.conf \ && /bin/sed -i "s@\${ENTRY_POINT_FILE}@$NGINX_ENTRY_POINT_FILE@" /etc/nginx/conf.d/application*.conf \ && /bin/sed -i "s@\${ALLOWED_FILES}@$NGINX_ALLOWED_FILES@" /etc/nginx/conf.d/application*.conf RUN mkdir -p /var/log/nginx EXPOSE 8071 9071 8070 9070 8056 9056 CMD ["nginx"] 15 — Srdjan Vranac, Code4Hire, PHPSrbija 2017

Slide 16

Slide 16 text

128 LAYERED CAEK (WAS 42) 16 — Srdjan Vranac, Code4Hire, PHPSrbija 2017

Slide 17

Slide 17 text

EXPECTO DOCKER 17 — Srdjan Vranac, Code4Hire, PHPSrbija 2017

Slide 18

Slide 18 text

$ docker run docker/whalesay cowsay boo Unable to find image 'docker/whalesay:latest' locally latest: Pulling from docker/whalesay e9e06b06e14c: Pull complete a82efea989f9: Pull complete 37bea4ee0c81: Pull complete 07f8e8c5e660: Pull complete 676c4a1897e6: Pull complete 5b74edbcaa5b: Pull complete 1722f41ddcb5: Pull complete 99da72cfe067: Pull complete 5d5bd9951e26: Pull complete fb434121fc77: Already exists Digest: sha256:d6ee73f978a366cf97974115abe9c4099ed59c6f75c23d03c64446bb9cd49163 Status: Downloaded newer image for docker/whalesay:latest _____ < boo > ----- \ \ \ ## . ## ## ## == ## ## ## ## === /""""""""""""""""___/ === ~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ / ===- ~~~ \______ o __/ \ \ __/ \____\______/ 18 — Srdjan Vranac, Code4Hire, PHPSrbija 2017

Slide 19

Slide 19 text

$ docker build -t docker-whale . Sending build context to Docker daemon 2.048 kB Step 1 : FROM docker/whalesay:latest ---> 6b362a9f73eb Step 2 : RUN apt-get -y update && apt-get install -y fortunes ---> Running in 05d4eda04526 Ign http://archive.ubuntu.com trusty InRelease Get:1 http://archive.ubuntu.com trusty-updates InRelease [65.9 kB] Get:2 http://archive.ubuntu.com trusty-security InRelease [65.9 kB] Hit http://archive.ubuntu.com trusty Release.gpg Hit http://archive.ubuntu.com trusty Release Get:3 http://archive.ubuntu.com trusty-updates/main Sources [480 kB] Get:4 http://archive.ubuntu.com trusty-updates/restricted Sources [5921 B] Get:5 http://archive.ubuntu.com trusty-updates/universe Sources [214 kB] Get:6 http://archive.ubuntu.com trusty-updates/main amd64 Packages [1160 kB] Get:7 http://archive.ubuntu.com trusty-updates/restricted amd64 Packages [20.4 kB] Get:8 http://archive.ubuntu.com trusty-updates/universe amd64 Packages [505 kB] Get:9 http://archive.ubuntu.com trusty-security/main Sources [157 kB] Get:10 http://archive.ubuntu.com trusty-security/restricted Sources [4621 B] Get:11 http://archive.ubuntu.com trusty-security/universe Sources [54.5 kB] Get:12 http://archive.ubuntu.com trusty-security/main amd64 Packages [700 kB] Get:13 http://archive.ubuntu.com trusty-security/restricted amd64 Packages [17.0 kB] Get:14 http://archive.ubuntu.com trusty-security/universe amd64 Packages [191 kB] Hit http://archive.ubuntu.com trusty/main Sources Hit http://archive.ubuntu.com trusty/restricted Sources Hit http://archive.ubuntu.com trusty/universe Sources Hit http://archive.ubuntu.com trusty/main amd64 Packages Hit http://archive.ubuntu.com trusty/restricted amd64 Packages Hit http://archive.ubuntu.com trusty/universe amd64 Packages Fetched 3640 kB in 11s (329 kB/s) 19 — Srdjan Vranac, Code4Hire, PHPSrbija 2017

Slide 20

Slide 20 text

Reading package lists... Reading package lists... Building dependency tree... Reading state information... The following extra packages will be installed: fortune-mod fortunes-min librecode0 Suggested packages: x11-utils bsdmainutils The following NEW packages will be installed: fortune-mod fortunes fortunes-min librecode0 0 upgraded, 4 newly installed, 0 to remove and 92 not upgraded. Need to get 1961 kB of archives. After this operation, 4817 kB of additional disk space will be used. Get:1 http://archive.ubuntu.com/ubuntu/ trusty/main librecode0 amd64 3.6-21 [771 kB] Get:2 http://archive.ubuntu.com/ubuntu/ trusty/universe fortune-mod amd64 1:1.99.1-7 [39.5 kB] Get:3 http://archive.ubuntu.com/ubuntu/ trusty/universe fortunes-min all 1:1.99.1-7 [61.8 kB] Get:4 http://archive.ubuntu.com/ubuntu/ trusty/universe fortunes all 1:1.99.1-7 [1089 kB] debconf: unable to initialize frontend: Dialog debconf: (TERM is not set, so the dialog frontend is not usable.) debconf: falling back to frontend: Readline debconf: unable to initialize frontend: Readline debconf: (This frontend requires a controlling tty.) debconf: falling back to frontend: Teletype dpkg-preconfigure: unable to re-open stdin: Fetched 1961 kB in 19s (101 kB/s) Selecting previously unselected package librecode0:amd64. (Reading database ... 13116 files and directories currently installed.) Preparing to unpack .../librecode0_3.6-21_amd64.deb ... 20 — Srdjan Vranac, Code4Hire, PHPSrbija 2017

Slide 21

Slide 21 text

Unpacking librecode0:amd64 (3.6-21) ... Selecting previously unselected package fortune-mod. Preparing to unpack .../fortune-mod_1%3a1.99.1-7_amd64.deb ... Unpacking fortune-mod (1:1.99.1-7) ... Selecting previously unselected package fortunes-min. Preparing to unpack .../fortunes-min_1%3a1.99.1-7_all.deb ... Unpacking fortunes-min (1:1.99.1-7) ... Selecting previously unselected package fortunes. Preparing to unpack .../fortunes_1%3a1.99.1-7_all.deb ... Unpacking fortunes (1:1.99.1-7) ... Setting up librecode0:amd64 (3.6-21) ... Setting up fortune-mod (1:1.99.1-7) ... Setting up fortunes-min (1:1.99.1-7) ... Setting up fortunes (1:1.99.1-7) ... Processing triggers for libc-bin (2.19-0ubuntu6.6) ... ---> dfaf993d4a2e Removing intermediate container 05d4eda04526 Successfully built c2c3152907b5 21 — Srdjan Vranac, Code4Hire, PHPSrbija 2017

Slide 22

Slide 22 text

$ docker run docker-whale ______________________________________ < You will be successful in your work. > -------------------------------------- \ \ \ ## . ## ## ## == ## ## ## ## === /""""""""""""""""___/ === ~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ / ===- ~~~ \______ o __/ \ \ __/ \____\______/ 22 — Srdjan Vranac, Code4Hire, PHPSrbija 2017

Slide 23

Slide 23 text

THINGS GET OUT OF HAND QUICKLY (COMMAND SAUSAGE FEST) docker run --rm -it --link web_service_container wernight/ngrok ngrok http web_service_container:80 docker run -d -v ~/nginxlogs:/var/log/nginx -p 5000:80 -i nginx 23 — Srdjan Vranac, Code4Hire, PHPSrbija 2017

Slide 24

Slide 24 text

THERE HAS TO BE A BETTER WAY 24 — Srdjan Vranac, Code4Hire, PHPSrbija 2017

Slide 25

Slide 25 text

DOCKER COMPOSE 25 — Srdjan Vranac, Code4Hire, PHPSrbija 2017

Slide 26

Slide 26 text

ANATOMY OF A COMPOSE FILE version: '2' services: web: build: . ports: - "5000:5000" volumes: - .:/code - logvolume01:/var/log links: - redis redis: image: redis volumes: logvolume01: {} 26 — Srdjan Vranac, Code4Hire, PHPSrbija 2017

Slide 27

Slide 27 text

.ENV version: '2' services: mysql: image: mysql volumes: - "${DATA_PATH}/mysql/db:/var/lib/mysql" environment: MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD} MYSQL_DATABASE: ${MYSQL_DATABASE} MYSQL_USER: ${MYSQL_USER} MYSQL_PASSWORD: ${MYSQL_PASSWORD} ports: - 3306:3306 27 — Srdjan Vranac, Code4Hire, PHPSrbija 2017

Slide 28

Slide 28 text

ROOTING OUT THE LUNACY 28 — Srdjan Vranac, Code4Hire, PHPSrbija 2017

Slide 29

Slide 29 text

/etc/subuid: vranac:1000:1 vranac:100000:65536 /etc/subgid: vranac:1000:1 vranac:100000:65536 29 — Srdjan Vranac, Code4Hire, PHPSrbija 2017

Slide 30

Slide 30 text

/proc/[PID]/uid_map: 0 1000 1 1 100000 65535 30 — Srdjan Vranac, Code4Hire, PHPSrbija 2017

Slide 31

Slide 31 text

/etc/docker/daemon.json: { "userns-remap": "vranac" } 31 — Srdjan Vranac, Code4Hire, PHPSrbija 2017

Slide 32

Slide 32 text

WOES OF A MAC 32 — Srdjan Vranac, Code4Hire, PHPSrbija 2017

Slide 33

Slide 33 text

PERFORMANCE 33 — Srdjan Vranac, Code4Hire, PHPSrbija 2017

Slide 34

Slide 34 text

DEMO TIME 34 — Srdjan Vranac, Code4Hire, PHPSrbija 2017

Slide 35

Slide 35 text

DOCKER-SYNC.IO 35 — Srdjan Vranac, Code4Hire, PHPSrbija 2017

Slide 36

Slide 36 text

DEMO TIME 36 — Srdjan Vranac, Code4Hire, PHPSrbija 2017

Slide 37

Slide 37 text

Networking docker0 Link encap:Ethernet HWaddr 02:42:43:64:dc:98 inet addr:172.17.0.1 Bcast:0.0.0.0 Mask:255.255.0.0 <-- This is what you want UP BROADCAST MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B) 37 — Srdjan Vranac, Code4Hire, PHPSrbija 2017

Slide 38

Slide 38 text

I want to connect from a container to a service on the host The Mac has a changing IP address (or none if you have no network access). Our current recommendation is to attach an unused IP to the lo0 interface on the Mac; for example: sudo ifconfig lo0 alias 10.200.10.1/24, and make sure that your service is listening on this address or 0.0.0.0 (ie not 127.0.0.1). Then containers can connect to this address. 38 — Srdjan Vranac, Code4Hire, PHPSrbija 2017

Slide 39

Slide 39 text

sudo ifconfig lo0 alias 10.254.254.254 255.255.255.0 39 — Srdjan Vranac, Code4Hire, PHPSrbija 2017

Slide 40

Slide 40 text

40 — Srdjan Vranac, Code4Hire, PHPSrbija 2017

Slide 41

Slide 41 text

OUR DOCKER DEVELOPMENT SETUP 41 — Srdjan Vranac, Code4Hire, PHPSrbija 2017

Slide 42

Slide 42 text

WHAT'S IN THE BOX - nginx server - php-fpm 5.6, 7.0, 7.1 and debug versions - php cli 5.6, 7.0, 7.1 - node - mailhog - redis - RabbitMq Optional: - ELK - Ngrok - Selenium standalone with firefox and chrome 42 — Srdjan Vranac, Code4Hire, PHPSrbija 2017

Slide 43

Slide 43 text

DEMO TIME 43 — Srdjan Vranac, Code4Hire, PHPSrbija 2017

Slide 44

Slide 44 text

THE END HTTPS://GITHUB.COM/CODE4HIRE/DOCKER-DEV-SETUP 44 — Srdjan Vranac, Code4Hire, PHPSrbija 2017