问题描述
我在 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 (将#修改为@)