Getting "FATAL: role" root "does not exist" when trying to make dockers

I am starting to work with an existing Rails project that uses Docker. I used Rails for a long time, but never Docker.

After execution, docker build .I try to do docker-compose up, but I get:

FATAL: the root role does not exist / usr / local / bundle / gems / activerecord -4.2.5.2 / lib / active_record / connection_adapters / postgresql_adapter.rb: 661: in `rescue in connect ': FATAL: the root role does not exist (ActiveRecord :: NoDatabaseError)

It seems to me that the Docker machine is probably trying to connect to the database as a user root, but there is no role called root, so the connection fails correctly.

I don’t know why Docker seems to be trying to connect to the database how rootand how to make it use the right user.

Here's mine database.yml:

development:
  database: my_app_development
  adapter: postgresql
  encoding: unicode
  pool: 5

Any help is appreciated.

Edit: here is my docker-compose.yml:

web:
  build: .
  volumes:
    - .:/my_app
  ports:
    - "3000:3000"
  links:
    - postgres
    - redis
    - mailcatcher
  env_file:
    - 'config/application.yml'
postgres:
  image: postgres:9.4
  ports:
    - "5432"
  env_file:
    - 'config/database.yml'
redis:
  image: redis:3.0.6
mailcatcher:
  image: schickling/mailcatcher
  ports:
    - "1080:1080"
+4
source share
3 answers

You might want to update your component and yml database as follows. With expected user and db's password database.yml. Alternatively, you can make this an environment variable. But first try the default for the dock dg postgres image as follows:

database.yml

development:
  database: my_app_development
  adapter: postgresql
  encoding: unicode
  pool: 5
  username: postgres
  password:
  host: postgres(db name in docker-compose.yml)

docker-compose.yml

      web:
        build: .
        command: bundle exec rails s -p 3000 -b '0.0.0.0'
        volumes:
          - .:/my_app
        ports:
          - "3000:3000"
        links:
          - postgres
          - redis
          - mailcatcher
      postgres:
        image: postgres:9.4
        ports:
          - "5432"
      redis:
        image: redis:3.0.6
      mailcatcher:
        image: schickling/mailcatcher
        ports:
            - "1080:1080"

I do not think you want to save

   env_file:
      - 'config/database.yml'

and

   env_file:
      - 'config/application.yml'

Then create the databases using docker-compose run web rake db:create

, , Dockerfile. docker build -t app-name ., docker-compose up.

+2

database.yml root, , . , database.yml :

development:
  database: my_app_development
  adapter: postgresql
  encoding: unicode
  pool: 5
  username: postgres

.

+1

docker-compose ; , , , docker-compose rm -v database .

docker-compose up --build .

Source: https://github.com/docker-library/postgres/issues/41#issuecomment-167603905

0
source

All Articles