我正在开发一些微服务和我的前端,当使用 docker-compose 构建前端和后端时,前端无法从模板文件夹中找到 home.html。当我将该应用程序作为常规 Flask 应用程序运行时,它运行良好。只有当我合并 Docker 时才会出现这个问题。├── backend│ ├── app.py│ ├── Dockerfile│ └── requirements.txt├── deployment.yaml├── docker-compose.yaml├── frontend│ ├── app.py│ ├── Dockerfile│ ├── requirements.txt│ └── templates│ ├── home.html│ ├── includes│ │ ├── _formhelpers.html│ │ ├── _messages.html│ │ └── _navbar.html│ └── layout.html└── README.md前端/app.pyfrom flask import Flask, jsonify, render_templateimport requestsimport jsonimport osapp = Flask(__name__)@app.route("/hello_world")def hello_world():be_host = os.getenv('BACKEND_SERVICE_HOST', 'backend')be_port = os.getenv('BACKEND_SERVICE_PORT', '5000')url = 'http://{}:{}/hello_world'.format(be_host, be_port)try: res = requests.get(url)except Exception: return "Error with {}".format(url)dictFromServer = res.json()return render_template('home.html', msg=dictFromServer['message'])if __name__=='__main__': app.run(debug=True, host='0.0.0.0')文件FROM python:3.6-alpineWORKDIR /appCOPY requirements.txt /appCOPY app.py /appRUN pip install -r requirements.txtEXPOSE 5000ENTRYPOINT ["python"]CMD ["app.py"]要求.txtFlaskrequestsjsonify
添加回答
举报
0/150
提交
取消