ufw + 码头工人 (56) Recv failure: Connection reset by peer

问题描述

我在 Windows 上的 VMWare 中使用 MX linux(基于 Debian)。 问题是在浏览器中启动后,没有返回结果(0.0.0.0:5000 or 127.0.0.1:5000 or localhost:5000)。

> curl 0.0.0.0:5000
curl: (56) Recv failure: Connection reset by peer
> curl 127.0.0.1:5000
curl: (56) Recv failure: Connection reset by peer
> curl localhost:5000
curl: (56) Recv failure: Connection reset by peer

完全按照页面 https://docs.docker.com/compose/gettingstarted/

上的文档进行操作

ufwset.sh

ufw reset
ufw default deny incoming
ufw default deny outgoing
ufw allow out on eth0 from any to {VPN_IP}
ufw allow out on tun0 from any to any
ufw allow out on docker0 from 172.17.0.0/16
ufw enable

如果不使用 Docker 运行,一切正常


app.py

import time

import redis
from flask import Flask

app = Flask(__name__)
cache = redis.Redis(host='redis',port=6379)

def get_hit_count():
    retries = 5
    while True:
        try:
            return cache.incr('hits')
        except redis.exceptions.ConnectionError as exc:
            if retries == 0:
                raise exc
            retries -= 1
            time.sleep(0.5)

@app.route('/')
def hello():
    count = get_hit_count()
    return 'Hello World! I have been seen {} times.\n'.format(count)

requirements.txt

flask
redis

Dockerfile

FROM python:3.7-alpine
workdir /code
ENV FLASK_APP=app.py
ENV FLASK_RUN_HOST=0.0.0.0
RUN apk add --no-cache gcc musl-dev linux-headers
copY requirements.txt requirements.txt
RUN pip install -r requirements.txt
EXPOSE 5000
copY . .
CMD ["flask","run","--host","0.0.0.0"]

docker-compose.yml

version: "3.9"
services:
  web:
    build: .
    ports:
      - "5000:5000"
  redis:
    image: "redis:alpine"

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...