Docker 2

docker-compose

Inštalácia

sudo curl -L "https://github.com/docker/compose/releases/download/1.29.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

# or

pip install docker-compose

Orchestrácia

https://www.docker.com/blog/containerized-python-development-part-2/

docker-compose.yml

  • version
  • services
  • networks
  • volumes

Config & Secrets

configs:
  # Krakend
  clientzone-gateway-endpoints:
    file: ./krakend/endpoints.json
    name: clientzone-gateway-endpoints
  
  clientzone-gateway-krakend:
    file: ./krakend/krakend.json
    name: clientzone-gateway-krakend


# V services
krakend:
    image: registry.gitlab.com/api-gateway
    networks:
      - internal-clientzone
      - traefik
    configs:
      - source: clientzone-gateway-endpoints
        target: "/etc/krakend/config/partials/endpoints.json"
      - source: clientzone-gateway-krakend
        target: "/etc/krakend/krakend.json"

Wordpress

version: "3.9"

services:
  db:
    image: mysql:5.7
    volumes:
      - db_data:/var/lib/mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: somewordpress
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: wordpress

  wordpress:
    depends_on:
      - db
    image: wordpress:latest
    ports:
      - "8000:80"
    restart: always
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpress
      WORDPRESS_DB_NAME: wordpress

volumes:
  db_data:

React, Express, MongoDB

version: "3.7"
services:
  frontend:
    build: frontend
    ports:
      - 3000:3000
    stdin_open: true # Aby sme mohli poslať signál na zastavenie
    volumes:
      - ./frontend:/usr/src/app
      - /usr/src/app/node_modules
    container_name: frontend
    restart: always
    networks:
      - react-express
    depends_on:
      - backend

  backend:
    container_name: backend
    restart: always
    build: backend
    volumes:
      - ./backend:/usr/src/app
      - /usr/src/app/node_modules
    depends_on:
      - mongo
    networks:
      - express-mongo
      - react-express
    expose: 
      - 3000
  mongo:
    container_name: mongo
    restart: always
    image: mongo:4.2.0
    volumes:
      - ./data:/data/db
    networks:
      - express-mongo
    expose:
      - 27017

networks:
  react-express:
  express-mongo:
FROM python:3.6 as base
RUN apt-get update && apt-get upgrade -y
RUN pip install pipenv pip
COPY Pipfile ./
# some more common configuration...

FROM base as dev
RUN pipenv install --system --skip-lock --dev
ENV FLASK_ENV development
ENV FLASK_DEBUG 1

FROM base as prod
RUN pipenv install --system --skip-lock
ENV FLASK_ENV production
# docker-compose.yml
version: '3.4'
services:
  webapp:
    build:
      context: ./dir
      dockerfile: Dockerfile
      target: prod

Python

Príkazy

docker-compose ps # Aktuálne služby
docker-compose logs # Logy
docker-compose run # Spustí jeden kontainer
docker-compose down # Zmaže kontajnery (odstrni aj restart: always)
docker-compose stop # Stopne
docker-compose up # Spustenie všetkých kontajnerov -d naštartuje na pozadí
docker-compose up -d --scale worker=5

docker-compose run -it app db:migrate

Kedy používať docker-compose

  • Lokálny vývoj
  • Deployment na menšiu Infra
  • Menšie prostredia - test, qa, prod
  • Swarm

Tips & tricks

  • docker-compose -p project-qa
docker-compose -p project-qa -f docker-compose.yml -f .compose/qa.yml
  • Env súbory
services:
  some-service:
    env_file:
      - a.env
      - b.env
  • Verzujte *.yml
Made with Slides.com