<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>

<p>Using the connection string as a URL worked:</p>

<pre class="lang-golang prettyprint-override"><code>    url := fmt.Sprintf("postgres://%v:%v@%v:%v/%v?sslmode=disable",
        pql.conf.Postgres.User,
        pql.conf.Postgres.Password,
        pql.conf.Postgres.Host,
        pql.conf.Postgres.Port,
        pql.conf.Postgres.DB)
</code></pre>

<p>See lib/pq docs here:
<a href="https://godoc.org/github.com/lib/pq" rel="noreferrer">https://godoc.org/github.com/lib/pq</a></p>

<p>I was stuck on this for more than a day and I owe the fix to Nikolay Sandalov's comment here in GitHub:
<a href="https://github.com/coreos/clair/issues/134#issuecomment-491300639" rel="noreferrer">https://github.com/coreos/clair/issues/134#issuecomment-491300639</a></p>

<p>Thank you, Nikolay 🙇🏻‍♂️</p>
