Docker-compose switch to version 2
More recently, after the release of Compose 1.6.0+ and Docker 1.10.0+ , version 2 became available .
Keys added: services , volumes , networks . The keys will be deleted: 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
Without links , but using env file .
fallback mode
While links work as before only 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'] %>
Without links , but using 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
Thanks for attention.