I spin up the docker container for postgres
docker run -i -t -v=":/var/lib/postgresql" -p 5432:5432 my_image/postgresql:9.3
And verify that it is reachable from host using
psql -h my_docker_ip -p 5432 -U pguser -W pgdb // passowrd: pguser
Now I want to connect to the container postgres
using go
in my host machine.
import (
"database/sql"
_ "github.com/lib/pq"
"fmt"
)
func main() {
db, err := sql.Open("postgres", "user=pguser password='pguser' host=192.168.99.100 port=5432 sslmode=verify-full")
if err != nil {
fmt.Println(err)
}
rows, err := db.Query("SELECT * FROM test")
fmt.Println(rows)
}
While there were no error on initializing the db instance reference, the test query itself print out
<nil>
This should not happen because I created table test
and multiple rows in table test
prior to running the go code.
Can someone tell me what I am doing wrong?
Thanks