title: fe_sendauth: no password supplied (PG::ConnectionBad) Docker container
body: <p>I followed a tutorial to dockerize an existing rails application. The app is running successfully in <strong>development</strong> env. But when I try to run as <strong>stating</strong> env I'm getting the error. I have kept same config for stating and development. Here are my related files:</p>
  
  <p><strong>database.yml</strong></p>
  
  <pre><code>default: &amp;default
    adapter: postgresql
    encoding: unicode
    pool: &lt;%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %&gt;
  
  development:
    &lt;&lt;: *default
    pool: 10
    timeout: 5000
    database: &lt;%= ENV['DATABASE_NAME'] %&gt;
    username: &lt;%= ENV['DATABASE_USER_NAME'] %&gt;
    password: &lt;%= ENV['DATABASE_PASSWORD'] %&gt;
    host: db
    port: 5432
  
  staging:
    &lt;&lt;: *default
    pool: 10
    timeout: 5000
    database: &lt;%= ENV['DATABASE_NAME'] %&gt;
    username: &lt;%= ENV['DATABASE_USER_NAME'] %&gt;
    password: &lt;%= ENV['DATABASE_PASSWORD'] %&gt;
    host: db
    port: 5432
  </code></pre>
  
  <p><strong>application.yml</strong></p>
  
  <pre><code>development:
    DATABASE_USER_NAME: 'developer'
    DATABASE_PASSWORD: 'qmwneb10PG'
    DATABASE_NAME: 'concern_box'
  staging:
    DATABASE_USER_NAME: 'developer'
    DATABASE_PASSWORD: 'qmwneb10PG'
    DATABASE_NAME: 'concern_box'
  </code></pre>
  
  <p><strong>docker-compose.yml</strong></p>
  
  <pre><code>version: '3'
  services:
    app:
      build: .
      container_name: cb_app_container
    db:
      container_name: cb_db_container
      image: postgres:9.6
      hostname: postgres
      ports:
        - "5432:5432"
  </code></pre>
  
  <p><strong>docker-compose.stag.yml</strong></p>
  
  <pre><code>version: '3'
  services:
    app:
      environment:
        RAILS_ENV: staging
      command: bundle exec rails s -p 80 -b '0.0.0.0'
      ports:
        - "80:80"
      depends_on:
        - db
  
    db:
      volumes:
        - ./tmp/db:/var/lib/postgresql/data
        - ./init.sql:/docker-entrypoint-initdb.d/init.sql
  </code></pre>
  
  <p><strong>docker-compose.dev.yml</strong></p>
  
  <pre><code>version: '3'
  services:
    app:
      command: bundle exec rails s -p 3000 -b '0.0.0.0'
      stdin_open: true
      tty: true
      volumes:
        - .:/concern-box
      ports:
        - "3001:3000"
      depends_on:
        - db
  
    db:
      volumes:
        - ./tmp/db:/var/lib/postgresql/data
        - ./init.sql:/docker-entrypoint-initdb.d/init.sql
  </code></pre>
  
  <p>init.sql</p>
  
  <pre><code>CREATE USER developer WITH PASSWORD 'qmwneb10PG';
  CREATE DATABASE concern_box;
  GRANT ALL PRIVILEGES ON DATABASE concern_box TO developer;
  </code></pre>
  
  <p>I'm using following commands to spin the containers <code>docker-compose -f docker-compose.yml -f docker-compose.dev.yml up --force-recreate</code> for development env and <code>docker-compose -f docker-compose.yml -f docker-compose.stag.yml up --force-recreate</code> to run as staging env.</p>