英文:
Docker: connection between golang webapp and postgres server refused
问题
我无法将我的Postgres容器与我的golang webapp容器连接起来。
我得到了以下错误:
panic: dial tcp [::1]:5432: getsockopt: connection refused
我的docker compose文件:
有什么办法可以解决这个问题吗?
英文:
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:
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).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论