Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Lessons learned using docker and docker-compose...

Lessons learned using docker and docker-compose for local development

Sergey Zhuravel

November 29, 2018

Transcript

24 slides
  1. This Document is Confidential Lessons learned using docker and docker-compose

    for local development Serhii Zhuravel dxops@github dxops@speakerdeck
  2. This Document is Confidential Init # docker-compose.yml: version: '3' services:

    web: build: . ports: - "5000:5000" redis: image: "redis:alpine" docker-compose up -d
  3. This Document is Confidential PHP service # php/php.yml: version: '2.3'

    services: backend: image: oroinc/php-71-centos7:latest
  4. This Document is Confidential PHP service mounts # docker-compose.yml: version:

    '2.3' services: backend: extends: file: php/php.yml service: backend volumes: - "./:/var/www/html/application"
  5. This Document is Confidential Lesson 1: Do not use file

    sync at all, its slow PHP and FPM on a host for a development EXPOSE 9000
  6. This Document is Confidential Lesson 2: Store generated files in

    a container volume • Exclude generated data from a file sync and put it into volumes • Do not use unnamed volumes
  7. This Document is Confidential Volumes # docker-compose.yml version: '2.3' services:

    backend: volumes: - "composer:/usr/local/composer:delegated" - "${ORO_PATH:-./}:/var/www/html/application:cached" - "vendor:/var/www/html/application/vendor:delegated" - "cache:/var/www/html/application/${SYMFONY_CACHE}:delegated" - "bundles:/var/www/html/application/${SYMFONY_WEB}/bundles:delegated" - "js:/var/www/html/application/${SYMFONY_WEB}/js:delegated" - "css:/var/www/html/application/${SYMFONY_WEB}/css:delegated" - "media:/var/www/html/application/${SYMFONY_WEB}/media:delegated"
  8. This Document is Confidential Volumes Definition # docker-compose.yml volumes: vendor:

    driver: local driver_opts: { type: tmpfs, device: tmpfs } name: ${COMPOSE_PROJECT_NAME:-default}_vendor data: driver: local driver_opts: { type: tmpfs, device: tmpfs } name: ${COMPOSE_PROJECT_NAME:-default}_data cache: driver: local driver_opts: { type: tmpfs, device: tmpfs } name: ${COMPOSE_PROJECT_NAME:-default}_cache
  9. This Document is Confidential PHP service versioning # php/php.yml: version:

    '2.3' services: backend: image: ${ORO_PHP_IMAGE:-oroinc/php-71-centos7}:latest # bash ORO_PHP_IMAGE:-oroinc/php-72-centos7 docker-compose up -d
  10. This Document is Confidential Dockerfile and Base Image # php/Dockerfile

    FROM centos/s2i-core-centos7 ARG ORO_PHP=70 RUN set -ex \ && yum -y --setopt=tsflags=nodocs install \ oro-php${ORO_PHP}
  11. This Document is Confidential Lesson 3: Base image • No

    Alpine • No Ubuntu • Centos like at OroCloud and Oro CI Servers
  12. This Document is Confidential Multiple Services Support Community Edition =

    MySQL or PostgreSQL, PHP, NGINX Enterprise Edition = Community Edition +RabbitMQ +ElasticSearch +Redis # docker-compose.yml: version: '2.3' services: backend: extends: file: php/php.yml service: backend env_file: - env/mail - env/websocket - env/${ORO_DB:-mysql} - env/${ORO_CACHE_TYPE:-file} - env/${ORO_SEARCH_ENGINE:-orm} - env/${ORO_MQ_TRANSPORT:-dbal}
  13. This Document is Confidential Env files # env/mysql ORO_DB_DRIVER=pdo_mysql ORO_DB_HOST=database

    ORO_DB_PORT=3306 ORO_DB_NAME=oro_db ORO_DB_USER=oro_db_user ORO_DB_PASSWORD=oro_db_pass
  14. This Document is Confidential Lesson 4: Config file includes #

    bash docker-compose -f docker-compose.yml up -d docker-compose -f docker-compose.yml -f enterprise.yml up -d
  15. This Document is Confidential Multiple Projects # bash ORO_PHP_IMAGE=oroinc/php-71-centos7 docker-compose

    -f docker-compose.yml -f enterprise.yml -p env1 up -d ORO_PHP_IMAGE=oroinc/php-71-centos7 docker-compose -f docker-compose.yml -f enterprise.yml -p env2 up -d ORO_PHP_IMAGE=oroinc/php-72-centos7 docker-compose -f docker-compose.yml -f enterprise.yml -p env3 up -d
  16. This Document is Confidential Execute commands Increased CLI command complexity:

    # bash ORO_PHP_IMAGE=oroinc/php-72-centos7 docker-compose -f docker-compose.yml -f enterprise.yml -p env1 exec -T backend composer install
  17. This Document is Confidential Lesson 5: Build and run, complex

    syntax support # Makefile COMPOSE_FILE:=docker-compose.yml:nterpise.yml COMPOSE_PROJECT_NAME=env1 # generated from a environment variables set export up: docker-compose up -d composer: up docker-compose exec -T backend composer install # bash make composer
  18. This Document is Confidential Extendability # Makefile # combine docker-compose.yml

    files # 1. default file from environment folder # 2. enterprise file from environment folder # 3. default file from application folder # 4. file from OVERRIDE_COMPOSE_FILE path COMPOSE_FILE:=$(realpath $(ORO_ENV))/docker/docker-compose.yml ifneq ($(EE),) COMPOSE_FILE:=$(COMPOSE_FILE):$(realpath $(ORO_ENV))/docker/enterprise.yml endif ifneq ($(wildcard $(ORO_PATH)/docker-compose.yml),) COMPOSE_FILE:=$(COMPOSE_FILE):$(ORO_PATH)/docker-compose.yml endif ifneq ($(wildcard $(OVERRIDE_COMPOSE_FILE)),) COMPOSE_FILE:=$(COMPOSE_FILE):$(OVERRIDE_COMPOSE_FILE) endif
  19. This Document is Confidential Lesson 6: All in one All

    in one is AIO 1. Makefile for your host 2. Use a single container 3. Put Makefile into container 4. Run it!
  20. This Document is Confidential Lesson 7: Host DNS No DNS

    container = No DNS at all Dnsmasq on a host + Traefik in a container to forward requests to a desired container, fallback to 1.1.1.1 \ 8.8.8.8
  21. This Document is Confidential Lessons X • Host Resources •

    File Permissions • Image Inheritance • Declarative Dockerfile Syntax • Maintenance Cost • Health Checks

More Decks by Sergey Zhuravel

Other Decks in Programming