Docker-compose switch to version 2

в 22:49, , рубрики: docker, docker-compose, nix, ruby on rails, разработка, метки:

image

Совсем недавно, после выхода Compose 1.6.0+ и Docker 1.10.0+, стала доступна 2 версия.
Добавлены ключи: services, volumes, networks. Будут удалены ключи: links.

Version 1

# docker-compose.yml
app:
  build: .
  ports:
    - '3000:3000'
  volumes:
    - .:/home/web
  links:
    - db
db:
  image: sameersbn/postgresql
  ports:
    - '5432'
  volumes_from:
    - db_data
  env_file:
    - $HOME/.docker/$APP/db.env
db_data:
  image: tianon/true
  volumes:
    - /var/lib/postgresql

# config/database.yml
development:
  adapter: postgresql
  encoding: unicode
  database: <%= ENV['DB_ENV_DB_NAME'] %>
  pool: 5
  username: <%= ENV['DB_ENV_DB_USER'] %>
  password: <%= ENV['DB_ENV_DB_PASS'] %>
  host: <%= ENV['DB_PORT_5432_TCP_ADDR'] %>

Version 2

fallback mode

Пока links работают по-старому только network_mode: bridge.
# docker-compose.yml
version: '2'
services:
  app:
    build: .
    ports:
      - '3000:3000'
    volumes:
      - .:/home/web
    depends_on:
      - db
    links:
      - db
    network_mode: bridge
  db:
    image: sameersbn/postgresql
    ports:
      - '5432'
    volumes:
      - db_data:/var/lib/postgresql
    env_file:
      - $HOME/.docker/$APP/db.env
    network_mode: bridge
volumes:
  db_data:

# config/database.yml
development:
  adapter: postgresql
  encoding: unicode
  database: <%= ENV['DB_ENV_DB_NAME'] %>
  pool: 5
  username: <%= ENV['DB_ENV_DB_USER'] %>
  password: <%= ENV['DB_ENV_DB_PASS'] %>
  host: <%= ENV['DB_PORT_5432_TCP_ADDR'] %>

Без links, но используя env file.

# docker-compose.yml
version: '2'
services:
  app:
    build: .
    ports:
      - '3000:3000'
    volumes:
      - .:/home/web
    depends_on:
      - db
    env_file:
      - $HOME/.docker/$APP/db.env
  db:
    image: sameersbn/postgresql
    ports:
      - '5432'
    volumes:
      - db_data:/var/lib/postgresql
    env_file:
      - $HOME/.docker/$APP/db.env
volumes:
  db_data:

# config/database.yml
development:
  adapter: postgresql
  encoding: unicode
  database: <%= ENV['DB_NAME'] %>
  pool: 5
  username: <%= ENV['DB_USER'] %>
  password: <%= ENV['DB_PASS'] %>
  host: <%= ENV['DB_HOST'] %>

# $HOME/.docker/$APP/db.env
DB_NAME=habrahabr
DB_USER=habrahabr
DB_PASS=habrahabr
DB_HOST=db

Спасибо за внимание.

Автор: AfsmNGhr

Источник

* - обязательные к заполнению поля


https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js