【问题标题】:Docker port expose issue, Recv failure: Connection reset by peerDocker 端口暴露问题,Recv 失败:对等方重置连接
【发布时间】: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


【解决方案1】:

如果你这样做:

http.ListenAndServe("localhost:8081", nil)

这将监听来自环回接口的连接。在容器中运行时,这将只接受来自该容器内的连接(或者如果您在 k8s pod 中运行它,则在同一个 pod 中)。所以:

http.ListenAndServe(":8081", nil)

这将接受环回和外部连接(容器外部)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-03
    • 1970-01-01
    相关资源
    最近更新 更多