首页 > 其他分享 >容器的接口访问错误:Recv failure: Connection reset by peer,Gin

容器的接口访问错误:Recv failure: Connection reset by peer,Gin

时间:2024-05-23 17:20:07浏览次数:11  
标签:reset 容器 ben 40000 博客园 failure Connection Gin localhost

go version go1.22.1 windows/amd64

Windows 11 + amd64

x86_64 x86_64 GNU/Linux

---

 

开发了一个 golang 程序:基于 Gin web 框架 的 服务,部署到了 ECS 的 容器(docker) 上,端口 40000 也暴露成功了。ben发布于博客园

# docker run -itd --name go1 -m 128MB -p 40000:40000 go1:v0.1

其中,go1:v0.1 是 自己 build 的 镜像。

 

在 宿主机访问出错:ben发布于博客园

#  curl -v http://localhost:40000/api/sys/info
*   Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 40000 (#0)
> GET /api/sys/info HTTP/1.1
> Host: localhost:40000
> User-Agent: curl/7.61.1
> Accept: */*
>
* Recv failure: Connection reset by peer
* Closing connection 0
curl: (56) Recv failure: Connection reset by peer

 容器的日志也查不到访问记录。

 

使用 docker exec 进入容器调用接口 成功。

 

为什么呢?

查询资料得知,这是 Gin web 框架的错误使用导致的。ben发布于博客园

问题代码:

import "github.com/gin-gonic/gin"
//...
router := gin.Default()
//...
router.Run("localhost:40000")

这里调用了 Run方法,其参数有一个 localhost,只是绑定到了 localhost,这就是错误的原因。

更改为如下即可

标签:reset,容器,ben,40000,博客园,failure,Connection,Gin,localhost
From: https://www.cnblogs.com/luo630/p/18208504

相关文章

  • ssh连接失败:kex_exchange_identification: read: Connection reset by peer
    现象docker内部在35001端口上开启ssh服务,通过容器所在主机登录ssh,成功。但通过其他机器登录ssh,失败。 解决方法关闭容器所在主机的防火墙。#查看firewall服务状态systemctlstatusfirewalld#查看firewall的状态firewall-cmd--state#开启servicefirewalldstar......
  • 解决postgres数据库remaining connection slots are reserved for non-replication su
    来源:【小工具】-解决postgres数据库remainingconnectionslotsarereservedfornon-replicationsuperuserconnectio-CSDN博客psycopg2.OperationalError:FATAL:remainingconnectionslotsarereservedfornon-replicationsuperuserconnection报错信息Traceback......
  • unity中animator中Trigger多次触发动画的解决方法(基于 stateInfo和ResetTrigger)
    巧妙地重置動畫控制器觸發(ResetTriggers)_哔哩哔哩_bilibili提出了FSMCleaSignals,会在进和出动画时使相关的trigger变为非激活状态,但是当该动作涉及多layer/多trigger控制时,会在该layer中动作未完成时,其他layer读取到了还未更改的异常激活状态的trigger,从而出错,这种错误主要是......
  • Java RMI遇到的Connection refused to Host: 127.x.x.x/192.x.x.x/10.x.x.x问题解决方
    问题故障解决记录--JavaRMIConnectionrefusedtohost:x.x.x.x....在学习JavaRMI时,我遇到了以下情况问题原因:可能大家的host是10或者192的私有地址,我估计都是和我一样的一个原因:/etc/hosts文件的配置问题(我是ubuntu系统下的实验环境),也就是主机名称和IP地址的映射关系......
  • HttpURLConnection 调用soap 并且使用Dom4j解析多层级XML为Map对象
    1.引入dom4j的maven依赖包<dependency><groupId>org.dom4j</groupId><artifactId>dom4j</artifactId><version>2.1.4</version></dependency>2.转map方法1importjava.io.BufferedReader;2importjava.io.InputStrea......
  • mysql报错:(1040, ‘ny connections‘)
    在项目、可视化数据库管理工具(比如:Navicat)连接Mysql数据库时出现:toomanyconnections的错误,偶现情况。原因是Mysql设置的最大连接数太小,连接池已满,实际连接数超过了mysql允许的最大连接数,访问量过高,MySQL服务器抗不住。解决:1、(推荐)修改max_connections,如果这个值已经很大,2、......
  • nginx 解决 No connection could be made because the target machine actively refus
    已经搭建好的环境突然全部nginx502,localhost拒绝访问报错信息:connect()failed(10061:Noconnectioncouldbemadebecausethetargetmachineactivelyrefusedit)whileconnectingtoupstream,client: 打开cmd,在cmd中ping127.0.0.1会出现下图情况。  ping......
  • Liunx部署NetCore,接口获取mysql本地数据时报:The SSL connection could not be establ
    今天将 NETCore程序发布到一台新的服务器,程序中有https请求第三方的Api,但是报了如下的错误:TheSSLconnectioncouldnotbeestablished,seeinnerexception解决办法下面命令查询openssl的路径opensslversion-a然后将CentOS默认的opensslCA证书拷贝到OPENSSLD......
  • openGauss connection-commit
    connection.commit()功能描述此方法将当前挂起的事务提交到数据库。注意:默认情况下,Psycopg在执行第一个命令之前打开一个事务:如果不调用commit(),任何数据操作的效果都将丢失。原型connection.commit()参数无。返回值无。示例请参见示例:常用操作。详情查看:https:/......
  • openGauss connection-close
    connection.close()功能描述此方法关闭数据库连接。注意:此方法关闭数据库连接,并不自动调用commit()。如果只是关闭数据库连接而不调用commit()方法,那么所有更改将会丢失。原型connection.close()参数无。返回值无。示例请参见示例:常用操作。详情查看:https://open......