一千萬個為什麽

搜索

Dockerized Flask:通過對等方重置連接



嘗試連接到dockerized Flask應用程序失敗,出現錯誤104,'使用此最小示例重置對等連接':

app.py:

from flask import Flask
app = Flask(__name__)

@app.route("/")
def hello():
    return "Hello World!"

if __name__ == "__main__":
    app.run()

Dockerfile:

FROM python:alpine
RUN pip install flask
COPY . /src/
EXPOSE 5000
ENTRYPOINT ["python", "/src/app.py"]

泊塢窗,compose.yml:

…
test:
    build: .
    ports:
        - 127.0.0.1:5000:5000

Flask app似乎按預期運行:

$ docker logs test 
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

嘗試從外部連接失敗:

$ http http://127.0.0.1:5000/
http: error: ConnectionError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer')) while doing GET request to URL: http://127.0.0.1:5000/

任何想法,為什麽我不能看到“Hello World!”這裏?

轉載註明原文: Dockerized Flask:通過對等方重置連接

一共有 1 個回答:

嘗試從外部連接失敗

你實際上是從外面連接的嗎? Flask綁定到localhost(127.0.0.1),只能從容器內訪問。如果你在本地機器上,你需要燒瓶綁定到所有IP:

from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello():
    return "Hello World!"

if __name__ == "__main__":
    app.run(host='0.0.0.0')

這對我成功。