本文介绍了go Scratch容器和PG容器之间的SSL连接问题。怎么解决?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我相信我已通过此连接解决了此问题...

I believe I resolved this issue with this connection...

db, err := gorm.Open("postgres", "host='postgres'&user:docker&port=5432&dbname='docker'&password='password'&sslmode=disable")






我之间的连接被拒绝一个Docker PG容器和一个GoLang Scratch容器。错误是:


I am getting a connection refused between a Docker PG container and a GoLang Scratch container. The error is:

============   exiting ==========
todo_1      | pq: SSL is not enabled on the server
todo_1      | panic: failed to connect database e

其他说明:


  • 我正在使用GORM库与PG连接。

请求:
请仔细检查代码,并提供一些提示,说明在何处以及如何解决此SSL问题。

REQUEST:Please look over code and give some hints on where and how to resolve this SSL issue.

推荐答案

您可以按照代码查找有关如何使用Postgres调用的文档。

You can follow the code to find the documentation on how to use the Postgres calls.


  • github.com/jinzhu/gorm调用

  • 数据库/ sql调用

  • lib / pq

和lib / pq ,包括:

And lib/pq documents it's usage including:

并且:

因此,没有SSL的数据库的连接字符串很简单:

So your connect string for a database without SSL is simply:

db, err := gorm.Open("postgres", "host='postgres' port=5432 user=docker dbname='docker' password='password' sslmode=disable")

或者您可以使用SSL密钥配置Postgres。这样做不是那么简单,但是要实现,您需要修改postgresql.conf文件以启用ssl设置,并将TLS密钥对作为卷(最好是群模式)进行安装。有关如何执行此操作的众多示例之一,请访问:

Or you could configure Postgres with an SSL key. That's less trivial, but to implement you'd need to modify the postgresql.conf file to enable the ssl settings and mount the TLS key pair as a volume, or preferably a secret with swarm mode. One of the many examples of how to do this can be found at: https://gist.github.com/likwid/86193ef581c530ea55d3

这篇关于go Scratch容器和PG容器之间的SSL连接问题。怎么解决?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 06:35