title: What postgres connection string on AWS docker multicontainer app?
body: <p>What Postgres connection string should I use if I run a docker multicontainer app via <code>Dockerrun.aws.js</code> on <em>AWS</em>?</p>
  
  <p>I have a Node.JS/Postgres/docker web-application. Postgres runs in its own container and so does the app. Locally, the app runs ok. When I deploy it to <em>AWS</em> via <em>ECR</em> and <em>BeanStalk</em>, the application successfully deploys and runs, but the web-app doesn't connect to Postgres.</p>
  
  <p>In <code>docker-compose.yaml</code>, the host in the connection string is the name of the container (in my case it would be <em>db</em>). That doesn't work with <em>AWS</em>. Neither does <code>localhost</code> or <code>127.0.0.1</code>.</p>
  
  <p>Here is my <code>Dockerrun.aws.js</code>:</p>
  
  <pre><code>{
    "AWSEBDockerrunVersion": 2,
    "volumes": [
      {
        "name": "db-data",
        "host": {
          "sourcePath": "/data/db"
        }
      }
    ],
    "containerDefinitions": [
      {
        "name": "db",
        "image": "db_image_name",
        "essential": true,
        "memory": 128,
        "environment": [
          {
            "name": "POSTGRES_USER",
            "value": "postgres"
          },
          {
            "name": "POSTGRES_PASSWORD",
            "value": "password"
          },
          {
            "name": "PGDATA",
            "value": "/data/db/pgdata"
          }
        ],
        "portMappings": [
          {
            "hostPort": 5432,
            "containerPort": 5432
          }
        ],
        "mountPoints": [
          {
            "sourceVolume": "db-data",
            "containerPath": "/data/db"
          }
        ]
      },
      {
        "name": "app",
        "image": "app_image_name",
        "essential": true,
        "memory": 128,
        "environment": [
          {
            "name": "NODE_ENV",
            "value": "production"
          },
          {
            "name": "DB_HOST",
            "value": "db"
          },
          {
            "name": "DB_PORT",
            "value": "5432"
          },
          {
            "name": "DB_PASSWORD",
            "value": "password"
          }
        ],
        "links": [
          "db"
        ],
        "portMappings": [
          {
            "hostPort": 80,
            "containerPort": 3000
          }
        ]
      }
    ]
  }
  </code></pre>
  
  <p>What should I put in the environment variable <strong>DB_HOST</strong>? (<em>DB_HOST</em> together with <em>DB_PORT</em> are used by the app to construct the connection string.) Thanks a lot.</p>