title: docker + golang lib/pq "dial tcp 127.0.0.1:5432: connect: connection refused"
body: <p><code>sql.Open()</code> wouldn't error:</p>
  
  <pre class="lang-golang prettyprint-override"><code>if db, err = sql.Open("postgres", url); err != nil {
      return nil, fmt.Errorf("Postgres connect error : (%v)", err)
  }
  </code></pre>
  
  <p>but <code>db.Ping()</code> would error:</p>
  
  <pre class="lang-golang prettyprint-override"><code>if err = db.Ping(); err != nil {
      return nil, fmt.Errorf("Postgres ping error : (%v)", err)
  }
  </code></pre>
  
  <p>and it was simply because the lib/pq connection string wouldn't connect from within a docker container with the seperated connection parameters.</p>
  
  <p>For example:</p>
  
  <pre class="lang-golang prettyprint-override"><code>url := fmt.Sprintf("user=%v password=%v host=%v port=%v dbname=%v",
      rs.conf.Redshift.User,
      rs.conf.Redshift.Password,
      rs.conf.Redshift.Host,
      rs.conf.Redshift.Port,
      rs.conf.Redshift.DB)
  </code></pre>