Toggle
本文介绍curl宿主机映射docker启动的服务端口报curl: (56) Recv failure: Connection reset by peer错误的排查步骤。
检查防火墙是否关闭
systemctl status -l firewalld
检查Ipv4转发是否开启
sysctl net.ipv4.ip_forward
检查容器是否启动
检测容器内端口是否启动
检测容器端口是否映射对,比如容器里启动的是80,你-p的时候映射成 -p 18000:81
检测容器是否监听0.0.0.0
# 错误写法1,容器监听没有绑定0.0.0.0
docker run -p 14444:8000 -it python:3.7-slim python3 -m http.server --bind 127.0.0.1
# 错误写法2,容器端口映射错误,容器是8000,映射的时候写成了8001
docker run -p 14444:8001 -it python:3.7-slim python3 -m http.server --bind 0.0.0.0
curl -v http://127.0.0.1:14444
* About to connect() to 127.0.0.1 port 14444 (#0)
* Trying 127.0.0.1...
* Connected to 127.0.0.1 (127.0.0.1) port 14444 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.29.0
> Host: 127.0.0.1:14444
> Accept: */*
* Recv failure: Connection reset by peer
* Closing connection 0
curl: (56) Recv failure: Connection reset by peer
# 正确写法
docker run -p 14444:8000 -it python:3.7-slim python3 -m http.server --bind 0.0.0.0
* About to connect() to 127.0.0.1 port 14444 (#0)
* Trying 127.0.0.1...
* Connected to 127.0.0.1 (127.0.0.1) port 14444 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.29.0
> Host: 127.0.0.1:14444
> Accept: */*
* HTTP 1.0, assume close after body
< HTTP/1.0 200 OK
< Server: SimpleHTTP/0.6 Python/3.7.9
< Date: Tue, 22 Dec 2020 05:32:37 GMT
< Content-type: text/html; charset=utf-8
< Content-Length: 987