【发布时间】:2020-11-18 20:41:37
【问题描述】:
我正在尝试在 docker 容器中运行 Go 应用程序二进制文件。该应用程序有一些 gRPC 请求正在侦听和服务器:
http.ListenAndServe("localhost:8081", nil)
在我的 docker-compose.yaml 中。我有一个映射到 8081 的应用服务:
golangAPP:
build:
context: .
dockerfile: ./docker/golangAPP/Dockerfile
depends_on:
- setup
ports:
- 8081:8081
在docker-compose up 之后,我可以看到正在提供应用程序的详细信息。
但我仍然无法到达它。 curl -X OPTIONS http://localhost:8081返回
curl: (56) Recv failure: Connection reset by peer
如果我在没有 docker 的情况下在本地运行二进制文件,那么我可以向应用发送请求。
有什么建议吗?我做了一些谷歌搜索和一些防火墙问题。但我不确定如何继续。
【问题讨论】:
-
使用这个:
http.ListenAndServe(":8081", nil) -
@BurakSerdar 就是这样。谢谢 !请提交您的答案。如果您也能解释原因,我将不胜感激。
标签: docker go networking