A
A
Alexander Korolev2016-02-18 09:23:45
Docker
Alexander Korolev, 2016-02-18 09:23:45

Why doesn't Docker-compose link the container to the database?

Good afternoon.
I'm trying to figure out docker-compose.
I did it on one project (rails): one container with an application that I build myself, the second one with a database (postgresql) - everything came together and worked:

web:
  build: .
  volumes:
    - .:/myapp
  ports:
    - "3000:3000"
  links:
    - db
  env_file:
    - '.env.web'
db:
  image: library/postgres:9.4.6
  ports:
    - "5432:5432"
  env_file:
    - '.env.db'

On the second project, I do everything in the same way, I just added one more image with redis:
web:
  build: .
  volumes:
    - .:/voip
  ports:
    - "3000:3000"
  links:
    - redis
    - db
  env_file:
    - '.env.web'
db:
  image: library/postgres:9.4.6
  ports:
    - "5432:5432"
  env_file:
    - '.env.db'
redis:
  image: redis
  ports:
    - "6379:6379"

But when building the container (sudo docker-compose build):
Couldn't create database for {"adapter"=>"postgresql", "encondig"=>"unicode", "pool"=>5, "username"=>"postgres", "database"=>db_production", "host"=>"db", "password"=>"mysecretpassword"}
rake aborted!
PG::ConnectionBad: could not translate host name "db" to address: Name or service not known

What could be the reason?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question