Dockerize your development setup

Dockerize your development setup

Everyone is talking about docker, containers, images, microservices but, very few
really talk about how to help developers get started in this whole new world.
This talk will give you an overview about docker, show you about basic concepts
you need to know to test the waters, point out some common pitfals,
and finally demonstrate the docker setup that cover most of your php needs
out of the box.

F2d82b268a7cbccc9809c939428df64f?s=128

Vranac Srdjan

March 21, 2017
Tweet

Transcript

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

    2017
  2. 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
  3. 3 — Srdjan Vranac, Code4Hire, PHPSrbija 2017

  4. 4 — Srdjan Vranac, Code4Hire, PHPSrbija 2017

  5. 5 — Srdjan Vranac, Code4Hire, PHPSrbija 2017

  6. 6 — Srdjan Vranac, Code4Hire, PHPSrbija 2017

  7. 7 — Srdjan Vranac, Code4Hire, PHPSrbija 2017

  8. 8 — Srdjan Vranac, Code4Hire, PHPSrbija 2017

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

  10. IMAGES 10 — Srdjan Vranac, Code4Hire, PHPSrbija 2017

  11. CONTAINERS 11 — Srdjan Vranac, Code4Hire, PHPSrbija 2017

  12. NETWORK $ docker network ls NETWORK ID NAME DRIVER 7fca4eb8c647

    bridge bridge 9f904ee27bf5 none null cf03ee007fb4 host host 12 — Srdjan Vranac, Code4Hire, PHPSrbija 2017
  13. VOLUMES 13 — Srdjan Vranac, Code4Hire, PHPSrbija 2017

  14. DOCKERFILE 14 — Srdjan Vranac, Code4Hire, PHPSrbija 2017

  15. FROM alpine:3.5 LABEL maintainer Srdjan Vranac <vranac@gmail.com> 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
  16. 128 LAYERED CAEK (WAS 42) 16 — Srdjan Vranac, Code4Hire,

    PHPSrbija 2017
  17. EXPECTO DOCKER 17 — Srdjan Vranac, Code4Hire, PHPSrbija 2017

  18. $ 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
  19. $ 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
  20. 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
  21. 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
  22. $ docker run docker-whale ______________________________________ < You will be successful

    in your work. > -------------------------------------- \ \ \ ## . ## ## ## == ## ## ## ## === /""""""""""""""""___/ === ~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ / ===- ~~~ \______ o __/ \ \ __/ \____\______/ 22 — Srdjan Vranac, Code4Hire, PHPSrbija 2017
  23. 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
  24. THERE HAS TO BE A BETTER WAY 24 — Srdjan

    Vranac, Code4Hire, PHPSrbija 2017
  25. DOCKER COMPOSE 25 — Srdjan Vranac, Code4Hire, PHPSrbija 2017

  26. 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
  27. .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
  28. ROOTING OUT THE LUNACY 28 — Srdjan Vranac, Code4Hire, PHPSrbija

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

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

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

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

    2017
  33. PERFORMANCE 33 — Srdjan Vranac, Code4Hire, PHPSrbija 2017

  34. DEMO TIME 34 — Srdjan Vranac, Code4Hire, PHPSrbija 2017

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

  36. DEMO TIME 36 — Srdjan Vranac, Code4Hire, PHPSrbija 2017

  37. 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
  38. 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
  39. sudo ifconfig lo0 alias 10.254.254.254 255.255.255.0 39 — Srdjan Vranac,

    Code4Hire, PHPSrbija 2017
  40. 40 — Srdjan Vranac, Code4Hire, PHPSrbija 2017

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

    2017
  42. 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
  43. DEMO TIME 43 — Srdjan Vranac, Code4Hire, PHPSrbija 2017

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