Docker:Golang Web应用程序与PostgreSQL服务器的连接被拒绝。

huangapple go评论78阅读模式
英文:

Docker: connection between golang webapp and postgres server refused

问题

我无法将我的Postgres容器与我的golang webapp容器连接起来。

我得到了以下错误:

panic: dial tcp [::1]:5432: getsockopt: connection refused

我的docker compose文件:

http://pastebin.com/5LQfn3gy

有什么办法可以解决这个问题吗?

英文:

I can't connect my Postgres container with my golang webapp container.

i got following error:

panic: dial tcp [::1]:5432: getsockopt: connection refused

My docker compose file:

http://pastebin.com/5LQfn3gy

Any idea how i can fix that?

答案1

得分: 0

由于您指定的IP地址与主机相关,而不是Docker环境,而且您也在Docker中运行应用程序,所以可以省略IP地址部分:

ports:
  - 5432:5432

因此,您只需要将Postgres的别名和端口传递给您的Go应用程序(可以作为环境变量或标志)。

英文:

Since the IP you specified relates to your host and not your docker environment and you're running your app inside docker too, just omit the IP:

ports:
  -5432:5432

So you'd just need to pass the Postgres alias, followed by its port to your go app (either as an env var or a flag).

huangapple
  • 本文由 发表于 2017年2月2日 21:07:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/42003078.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定