使用docker-compose up启动服务后访问报错curl: (56) Recv failure: Connection reset by peer。
curl -v 127.0.0.1:8000
[root@iZhp33j6fklnmhbf0lz2obZ admin]# curl -v 127.0.0.1:8000
* Rebuilt URL to: 127.0.0.1:8000/
* Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to 127.0.0.1 (127.0.0.1) port 8000 (#0)
> GET / HTTP/1.1
> Host: 127.0.0.1:8000
> User-Agent: curl/7.61.1
> Accept: */*
>
* Recv failure: Connection reset by peer
* Closing connection 0
curl: (56) Recv failure: Connection reset by peer
外部访问telnet接口能通。
[root@iZhp33j6fklnmhbf0lz2obZ admin]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f4571922817f admin_web "python app.py" 3 minutes ago Up 3 minutes 0.0.0.0:8000->3000/tcp, :::8000->3000/tcp admin_web_1
进入容器内部查看端口是否正常一致。
docker exec -it admin_web_1 /bin/sh
netstat -ntlp
[root@iZhp33j6fklnmhbf0lz2obZ admin]# docker exec -it admin_web_1 /bin/sh
/usr/local/bin # netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:5000 0.0.0.0:* LISTEN 1/python
tcp 0 0 127.0.0.11:41025 0.0.0.0:* LISTEN -
从容器内部发现端口3000并不存在,只有5000端口(flask默认端口),证明端口没对应上。
修改docker-compose.yml文件端口保证一致。
version: '3'
services:
web:
build: .
ports:
- "8000:5000"
volumes:
- .:/code
redis:
image: "redis:alpine"
python文件:
from flask import Flask
app = Flask(__name__)
@app.route("/")
def index():
return 'Hello World! '
if __name__ == "__main__":
# 设置运行信息
app.run(host="0.0.0.0", debug=True)
MySQL默认端口 3306
Redis默认端口 6379
MongoDB默认端口 27017
django端口 8000
flask端口 5000
pyspider服务端口 5000(由flask开发)
gerapy服务端口 8000(由django开发)
scrapyd服务端口 6800
ipython notebook 默认端口 8888
HTTP默认端口 80
HTTPS服务默认端口443
点赞 收藏 关注