我正在openshift 4.7中尝试以https模式运行python flask应用程序。我让我的python flask应用程序监听端口8080,该端口通过dockerFile配置公开,如下所示。我已经通过Openshift控制台中的配置重定向了https请求,方法是对https port 443 to pod port 8080
执行Service Port Mapping
。您可以通过转到OpenshiftConsole > Project > Services > Service Details
并选择您的应用程序来配置此功能。但我仍然无法在https模式下访问该服务。当我尝试以https模式访问时,我得到错误The application is currently not serving requests at this endpoint. It may not have been started or is still starting.
当我通过oc cli进行正常部署,而不通过openshift控制台进行任何ssl配置时,该应用程序在http模式下运行良好。请告知如何在https模式下运行此功能
下面是我的app.py代码
from flask import Flask, jsonify, request, redirect
app = Flask(__name__)
@app.route('/<string:name>/')
def helloName(name):
print(request)
return "Hello " + name
if __name__ == "__main__":
app.run(host='0.0.0.0', port=8080, debug = True)
我的Dockerfile内容如下,我正在从中暴露端口8080
# set base image
FROM registry.redhat.io/rhel8/python-38
# copy the dependencies file to the working directory
COPY requirements.txt .
# Configure PIP with local Nexus
ENV PIP_TRUSTED-HOST=nexus.company.com:8443
ENV PIP_INDEX=https://nexus.company.com:8443/repository/pypi-group/pypi
ENV PIP_INDEX-URL=https://nexus.company.com:8443/repository/pypi-group/simple
ENV PIP_NO-CACHE-DIR=false
ENV PIP_TIMEOUT=600
RUN touch ~/.netrc && \
echo "machine nexus.company.com" >> ~/.netrc && \
echo "login ${NEXUS_USER}" >> ~/.netrc && \
echo "password ${NEXUS_TOKEN}" >> ~/.netrc
# install dependencies
RUN pip install -U pip \
pip install -r requirements.txt
# copy the content of the local src directory to the working directory
COPY src/ .
EXPOSE 8080
# command to run on container start
CMD [ "python3", "./app.py" ]
Requirements.txt只有一个烧瓶
这里有两件事:
使用host=“0.0.0.0”时,Flask将侦听其运行的机器的IP。我认为将其更改为127.0.0.1应该是好的
app.run(host='127.0.0.1', port=8080, debug = True)
可能更重要的是,Flask中的
.run()
方法仅用于开发,对于生产,您应该使用gunicorn之类的方法链接:https://gunicorn.org/
干杯,T
相关问题 更多 >
编程相关推荐