Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Neos Conference 2019: Docker for Development

226 views

Published on

Are you using Docker for development, because … it’s the future? And sometimes wish you had your boring, but nicely working development environment back? Containers certainly are the future, now let’s identify and sort out all those little problems which keep you from using it today effectively.

When Docker hit the scene, many developers (including me) started using containers as a lightweight alternative to virtual machines. It was promising to use Docker as a local environment for development which would closely match the software running on the production servers. But the cake was a lie, all sorts of practical issues spoiled the fun.​

In this session I’ll share what I learned throughout the last four years of using Docker as a development (and production) environment and how you can create your own set-up taking full advantage of the benefits containers provide. See an example for a fully working solution tailored to Neos and Flow and learn how it works internally

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Neos Conference 2019: Docker for Development

  1. 1. Docker for Development by Robert Lemke
  2. 2. Robert Lemke Flownative Managing Partner
 Neos Project Founder
 
 robert@flownative.com
 @robertlemke
  3. 3. Some Blue Slide
  4. 4. Goals for my Local Development Environment
  5. 5. Goals for my local development environment No compromise on tooling
  6. 6. fastfastfast
  7. 7. Easy to setup Easy to switch
  8. 8. Development software versions should match production
  9. 9. Additional software like Redis or Elasticsearch
 should be set up easily & match production
  10. 10. Composer must use the correct production environment
  11. 11. Options without Docker
  12. 12. Install multiple PHP, MariaDB, Apache, Redis, Elasticsearch, Nginx, Solr … versions
  13. 13. Use a clever combination of dnsmasq resolv hosts
  14. 14. and how’s your current setup?
  15. 15. Options with Docker
  16. 16. Docker Compose with Nginx, PHP-FPM, MySQL Mounted Volumes
  17. 17. Problem #1 Cumbersome setup
  18. 18. create templates & scripts
  19. 19. introduce a standardized docker-compose.yml 
  20. 20. take advantage of
 .env files maybe even create
 a cascade
  21. 21. Problem #2 Port management
  22. 22. Problem #3 Slow file access
  23. 23. Why are mounted volumes so slow * 
 * on Mac and Windows
  24. 24. option #1: don't mount the volume but work with Git inside the container
  25. 25. option #2: using cached and delegated
 as volume options
  26. 26. examples:
 consistent, cached, delegated
  27. 27. Source: https://blog.docker.com/2017/05/user-guided-caching-in-docker-for-mac/
  28. 28. consistent Container and host views are always synchronized
  29. 29. cached Host’s view of file system is authoritative. Writes performed on host may take time until they appear in within containers.
  30. 30. delegated Provides weakest set of guarantees. 
 Container’s view of file system is authoritative.
  31. 31. option #3: mount certain directories,
 use rsync for others
  32. 32. Problem #4 SSH access
  33. 33. Problem #5 Sync data from or to production
  34. 34. Problem #6 Using Composer in the right environment
  35. 35. Local Beach https://flownative.com/localbeach
  36. 36. Demo
  37. 37. version: '3' networks: local_beach: external: name: local_beach services: webserver: image: ${BEACH_WEBSERVER_IMAGE:-flownative/beach-nginx}:${BEACH_WEBSERVER_IMAGE_VERSION:-latest} container_name: ${BEACH_PROJECT_NAME:?Please specify a Beach project name as BEACH_PROJECT_NAME}_webserver networks: - local_beach ports: - "80" volumes: - .:/application:delegated environment: - VIRTUAL_HOST=${BEACH_PROJECT_NAME}.localbeach.net - BEACH_PHP_FPM_HOST=${BEACH_PROJECT_NAME:?Please specify a Beach project name as BEACH_PROJECT_NAME}_php.local_beach - BEACH_FLOW_BASE_CONTEXT=${BEACH_FLOW_BASE_CONTEXT:-Development} - BEACH_FLOW_SUB_CONTEXT=${BEACH_FLOW_SUB_CONTEXT:-Instance} - BEACH_PHP_MEMORY_LIMIT=${BEACH_PHP_MEMORY_LIMIT:-750M} php: image: ${BEACH_PHP_IMAGE:-flownative/beach-phpfpm}:${BEACH_PHP_IMAGE_VERSION:-latest} container_name: ${BEACH_PROJECT_NAME:?Please specify a Beach project name as BEACH_PROJECT_NAME}_php networks: - local_beach ports: - "${BEACH_SSH_PORT:-2222}:22" depends_on: - webserver - redis volumes: - ./Data/Persistent:/application/Data/Persistent:delegated - ./Data/Logs:/application/Data/Logs:delegated - ./Data/DoctrineMigrations:/application/Data/DoctrineMigrations - .:/application-on-host:delegated - ./.LocalBeach/secrets:/secrets - ./.LocalBeach/home:/home/beach - ./Web:/application/Web:delegated environment: - BEACH_PHP_FPM_ENABLE=true .localbeach.docker-compose.yaml
  38. 38. # # Environment variables for the Local Beach Docker Compose setup # BEACH_PROJECT_NAME=neos-demo # Change the PHP version to the branch you use in your Beach instances. # Examples: 7.3 for PHP 7.3.x BEACH_PHP_IMAGE_VERSION=7.3 # If you are running multiple Local Beach projects on your computer, # set the following port to a value which is not used by other projects # or applications yet: BEACH_SSH_PORT=2122 .localbeach.dist.env
  39. 39. Docker in Production
  40. 40. docker-compose
  41. 41. Kubernetes
  42. 42. Flownative Beach
  43. 43. robert@flownative.com www.flownative.com @robert@flownative.social
  44. 44. #!/bin/bash ######### Configuration ######### ## Whether to enable verbosity. If enabled, change events are output. if [ -z "${INOTIFY_VERBOSE}" ]; then INOTIFY_VERBOSE=0 fi ################################## inotifywait -m -q -r -e CREATE -e DELETE -e MODIFY -e MOVED_FROM -e MOVED_TO --exclude '(.git/|.idea/| .Docker/|.syncd.conf|Data/|Web/|___jb_)' --format '%e %w%f' /application-on-host | while read EVENT FILE do case ${EVENT} in 'DELETE'|'MOVED_FROM') COMMAND="rm -f '${FILE//application-on-host///application/}'" ;; 'DELETE,ISDIR'|'MOVED_FROM,ISDIR') COMMAND="rm -rf '${FILE//application-on-host///application/}'" ;; 'CREATE,ISDIR'|'MOVED_TO,ISDIR'|'MODIFY,ISDIR') COMMAND="[ -d "${FILE}" ] && cp -rpLf '${FILE}' '$(dirname ${FILE//application-on-host/// application/})'" ;; 'CREATE'|'MOVED_TO'|'MODIFY') COMMAND="[ -f "${FILE}" ] && cp -pLf '${FILE}' '${FILE//application-on-host///application/}'" ;; *) COMMAND='# "Unhandled event ${EVENT}"' ;; esac if [ ${INOTIFY_VERBOSE} -ne 0 ]; then echo "[${EVENT}] ${FILE}" echo " ${COMMAND}" fi eval ${COMMAND} done
  45. 45. #!/bin/bash #------------------------------------------------------------ # based on https://github.com/drunomics/syncd # initd script for running services without start-stop-daemon # (c) Wolfgang Ziegler, nuppla@zites.net, drunomics GmbH #------------------------------------------------------------ CONF_FILE=/application-on-host/.syncd.conf PIDFILE="/var/run/syncd.pid" LOGFILE="/var/log/syncd.log" INOTIFY_VERBOSE=0 if [ -e ${CONF_FILE} ]; then . ${CONF_FILE} fi SCRIPT=`readlink -f $0` DAEMON_NAME=syncd LINK=`readlink -f $0` SCRIPT_DIR=`dirname ${LINK}` case $1 in start) if [ -e ${PIDFILE} ] && ( ps -p `cat ${PIDFILE}` > /dev/null ); then echo "$DAEMON_NAME is already running." exit 1; fi export INOTIFY_VERBOSE ${SCRIPT_DIR}/watch.sh >> ${LOGFILE} & echo "$!" > ${PIDFILE} echo "Starting $DAEMON_NAME..." ;; stop) if [ ! -e ${PIDFILE} ] || ( ! ps -p `cat ${PIDFILE}` > /dev/null ); then echo "$DAEMON_NAME is not running." exit 1; fi

×