title: Rails 5 in prod: PG::ConnectionBad: FATAL: password authentication failed for user "postgres" with Docker
body: <p>I am seeing the following error on my Linode server (Ubuntu 17.04) when starting up my Rails app:</p>
  
  <pre><code>PG::ConnectionBad: FATAL:  password authentication failed for user "postgres"
  </code></pre>
  
  <p>The odd thing is that this is only happening on my remote server. Locally (on my Mac), it's working fine. I have the following docker-compose.yml file:</p>
  
  <pre><code>version: "2"
  services:
    postgres:
      image: postgres:9.6
      ports:
        - "5432:5432"
      environment:
        POSTGRES_DB: "${DATABASE_NAME}"
        POSTGRES_PASSWORD: "${DATABASE_PASSWORD}"
      volumes:
        - postgres-data:/var/lib/postgresql/data
    redis:
      image: redis:latest
      ports:
        - "6379:6379"
  volumes:
    postgres-data:
      driver: local
  </code></pre>
  
  <p>which should bind Postgres to port 5432 on localhost and set the password to the DATABASE_PASSWORD environment variable. If I run <code>ps aux | grep 5432</code> on the server I can see the Docker process is running correctly:</p>
  
  <pre><code>root     29550  0.0  0.2  34472  2888 ?        Sl   01:34   0:00 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 5432 -container-ip 172.18.0.3 -container-port 5432
  </code></pre>
  
  <p>So I cannot figure out why I'm getting a password authentication failed error message.</p>
  
  <p>My config/database.yml file:</p>
  
  <pre><code>default: &amp;default
    adapter: postgresql
    encoding: unicode
    pool: &lt;%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %&gt;
    host: localhost
    username: postgres
  
  ...
  
  production:
    &lt;&lt;: *default
    database: &lt;%= ENV['DATABASE_NAME'] %&gt;
    password: &lt;%= ENV['DATABASE_PASSWORD'] %&gt;
  </code></pre>
  
  <p>The variables are set in my environment and I am able to echo them properly from the shell.</p>
  
  <p>Any help would be much appreciated! Thanks</p>