5 posts tagged

docker-compose

Well, this issue was my pain in the ass until I fully understood what was going on with nginx-proxy container and docker-compose v2.

When you have docker-compose.yml with separate frontend network you need to connect this network to nginx-proxy container in order to work. Obviously, there is no frontend network until you up your containers for the first time!
When you do

docker-compose up

network will be created, but nginx-proxy will not be attached to it! So you need to shut down your app containers, do

docker network connect itservice_frontend-tier nginx-proxy

and then to fire your containers up again! But wait, you need to restart nginx-proxy container to connect to this new network!

As you can see this process can not be single step deployment solution on CoreOS, but now you know why and how to fix this.

dockerdocker-composenginxngix-proxy
  1. Bundle package will create a cached copy, so bundler in docker will not fetch all dependencies all the time.
bundle package
  1. Create separate bundler data volume to perisist bundle between builds. Set BUNDLE_PATH to data volume. You can include this option just for development docker-compose.yml file and not to include in production.
version: "2"

services:
  memcached:
    image: memcached
    networks:
      - back-tier
  redis:
    image: redis
    ports: ["6379"]
    networks:
      - back-tier
  db:
    image: mysql:5
    volumes:
      - ./sql:/docker-entrypoint-initdb.d
      - mysql:/var/lib/mysql
    networks:
      - back-tier

  sse:
    image: mprokopov/sse
    build:
      context: sse/.
    command: "bundle exec rackup --host 0.0.0.0 --port 9292"
    environment:
      - RACK_ENV=production ## docker database settings in config.yml
    ports:
      - "9292:9292"
    links:
      - redis
      - db
    depends_on:
      - db
      - redis
    networks:
      - back-tier
      - front-tier

  worker:
    image: mprokopov/itservice_web_dev
    command: "bundle exec rake environment resque:work"
    environment:
      - QUEUE=*
    links:
      - db
      - redis
    depends_on:
      - db
      - redis
    networks:
      - back-tier

  worker-schedule:
    image: mprokopov/itservice_web_dev
    command: "bundle exec rake environment resque:scheduler"
    links:
      - db
      - redis
    depends_on:
      - redis
    networks:
      - back-tier

  search:
    image: mprokopov/itservice_search
    build: ./search
    volumes:
      - search-data:/search
    depends_on:
      - db
    links:
      - db
    networks:
      - back-tier
    expose:
      - "9306"
  web:
    ports:
      - "3000:3000"
    environment:
      - LETTER_OPENER=letter_opener_web
      - RAILS_SERVE_STATIC_FILES=true
      - SLACK_NOTIFICATION=false
      - EMAIL_NOTIFICATION=false
      - SLACK_WEBHOOK_CHANNEL=#events_test
      - STREAM_API=http://localhost:9292
    depends_on:
      - db
      - redis
    links:
      - db
      - redis
      - search
    networks:
      - back-tier
      - front-tier
    volumes:
      - search-data:/search

volumes:
  search-data:
  mysql:

networks:
  back-tier:
  front-tier:
  1. Use docker-compose.override.yml for development and docker-compose.prod.yml for production builds. Create docker-compose.yml which contains common services configuration.
version: "2"

services:
  db:
    environment:
      - MYSQL_DATABASE=itservice_development
      - MYSQL_USER=
      - MYSQL_ROOT_PASSWORD=
      - MYSQL_PASSWORD=

  sse:
    environment:
      - MYSQL_DATABASE=itservice_development
      - MYSQL_USER=
      - MYSQL_PASSWORD=
      - MYSQL_HOST=db
      - REDIS_HOST=redis
      - RACK_ENV=production ## docker database settings in config.yml

  worker:
    environment:
      - RAILS_ENV=development

  worker-schedule:
    environment:
      - RAILS_ENV=development

  search:
    environment:
      - SPHINX_ENV=development
  web:
    image: mprokopov/itservice_web_dev
    command: bundle exec rails s -b 0.0.0.0 -p 3000
    environment:
      - RAILS_ENV=development
      - LETTER_OPENER=letter_opener_web
      - RAILS_SERVE_STATIC_FILES=true
      - SLACK_NOTIFICATION=false
      - EMAIL_NOTIFICATION=false
      - SLACK_WEBHOOK_CHANNEL=#events_test
      - STREAM_API=http://localhost:9292
      - BUNDLE_PATH=/bundle
    volumes:
      - bundle:/bundle
      - ./app:/app

volumes:
  bundle:
  1. Use docker-compose.prod.yml as docker-compose.override.yml in production, so you will save necessary keystrokes, because docker-compose will use override.yml by default.
  2. Use nginx-proxy container in production and gem unicorn/puma or thin.
    connect nginx-proxy container to frontend network like this
docker network connect itservice_front-tier nginx-proxy

It will enable to use nginx-proxy with docker-compose v2 syntax.

  1. In case you're using CoreOS or systemd you can create container backups via custom backup service and Timer for that service.

нужно просто добавить контейнер в сеть с nginx-proxy примерно так

docker network add mynet_default nginx-proxy

и все работает.

Либо добавлять external: bridge через docker-compose.

dockerdocker-composenginx

предварительно перейдя в sudo -s

curl -sS https://gist.githubusercontent.com/marszall87/ee7c5ea6f6da9f8968dd/raw/9f3a037ea0f294bdf5d835fa72cfadf0b95e4ca3/docker-compose-install.sh | bash
coreosdocker-compose
Dec 25, 2015, 15:43

MySQL collation in docker

в docker-compose.yml

db:
  image: mysql:5
  environment:
    - MYSQL_DATABASE=vtiger
    - MYSQL_USER=vtiger
    - MYSQL_PASSWORD=nexus-bla
    - MYSQL_ROOT_PASSWORD=nexus-bla
  command:
    - --character-set-server=utf8
    - --collation-server=utf8_general_ci