第一次使用Docker(19.03.5版)并尝试此教程
我被困在步骤2.3.4中运行一个映像
当我去http://localhost:8888时我看到了
Internal Server Error The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.
我将Dockerfile更新为与我的目录相匹配:
# our base image
FROM alpine:3.5
# Install python and pip
RUN apk add --update py2-pip
# install Python modules needed by the Python app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# copy files required for the app to run
COPY app.py .
COPY templates/index.html templates
# tell the port number the container should expose
EXPOSE 5000
# run the application
CMD ["python", "app.py"]在我的命令行里
C:\Users\user\docker\flask-app>docker run -p 8888:5000 --name flask-app 11111111/flask-app
* Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
当我访问提示符上的页面时
172.17.0.1 - - [05/Jan/2020 07:14:34] "GET / HTTP/1.1" 500 -
我的app.py里有这个
from flask import Flask, render_template
import random
app = Flask(__name__)
# list of cat images
images = [
"http://img.buzzfeed.com/buzzfeed-static/static/2013-10/enhanced/webdr05/15/9/anigif_enhanced-buzz-26388-1381844103-11.gif",
"http://img.buzzfeed.com/buzzfeed-static/static/2013-10/enhanced/webdr01/15/9/anigif_enhanced-buzz-31540-1381844535-8.gif",
"http://img.buzzfeed.com/buzzfeed-static/static/2013-10/enhanced/webdr05/15/9/anigif_enhanced-buzz-26390-1381844163-18.gif",
"http://img.buzzfeed.com/buzzfeed-static/static/2013-10/enhanced/webdr06/15/10/anigif_enhanced-buzz-1376-1381846217-0.gif",
"http://img.buzzfeed.com/buzzfeed-static/static/2013-10/enhanced/webdr03/15/9/anigif_enhanced-buzz-3391-1381844336-26.gif",
"http://img.buzzfeed.com/buzzfeed-static/static/2013-10/enhanced/webdr06/15/10/anigif_enhanced-buzz-29111-1381845968-0.gif",
"http://img.buzzfeed.com/buzzfeed-static/static/2013-10/enhanced/webdr03/15/9/anigif_enhanced-buzz-3409-1381844582-13.gif",
"http://img.buzzfeed.com/buzzfeed-static/static/2013-10/enhanced/webdr02/15/9/anigif_enhanced-buzz-19667-1381844937-10.gif",
"http://img.buzzfeed.com/buzzfeed-static/static/2013-10/enhanced/webdr05/15/9/anigif_enhanced-buzz-26358-1381845043-13.gif",
"http://img.buzzfeed.com/buzzfeed-static/static/2013-10/enhanced/webdr06/15/9/anigif_enhanced-buzz-18774-1381844645-6.gif",
"http://img.buzzfeed.com/buzzfeed-static/static/2013-10/enhanced/webdr06/15/9/anigif_enhanced-buzz-25158-1381844793-0.gif",
"http://img.buzzfeed.com/buzzfeed-static/static/2013-10/enhanced/webdr03/15/10/anigif_enhanced-buzz-11980-1381846269-1.gif"
]
@app.route('/')
def index():
url = random.choice(images)
return render_template('index.html', url=url)
if __name__ == "__main__":
app.run(host="0.0.0.0")我不明白为什么我的页面没有加载。任何帮助都将不胜感激。
注意:我已经安装了WAMP,这可能是相互冲突的,但不确定是否是这样和/或如何修复它。
发布于 2020-02-02 15:23:33
烧瓶可能无法找到您的模板。试着改变
COPY templates/index.html templates至
COPY templates templates将./templates中的所有内容复制到<WORKDIR>/templates。
使用COPY templates/index.html templates将index.html复制为路径<WORKDIR>/templates中的文件,而不是在该目录下复制它。
发布于 2020-02-01 21:06:41
如何在Docker中调试您的Flask应用程序:
ENV FLASK_DEBUG=1添加到您的Dockerfile中,打开Flask调试器pdb来调试容器中的应用程序。对于初学者来说,这可能很难,但总的来说,这是一项基本的技能。检查在Docker容器中调试Python烧瓶应用程序以获得一步一步的指南.发布于 2020-02-01 19:43:03
注意:这更多的是针对“我如何调试”这个问题。目前还不清楚OP是否真的想要一个解决方案,而不是解决这个问题的方法。
首先要做的是在没有应用程序的情况下启动容器。为此,您可以将CMD ["python", "app.py"]替换为CMD ["sleep", "inf"]。现在,启动容器之后,可以使用docker exec -it flask-app /bin/bash在容器中获得一个shell。在shell中,您可以使用常规的Python调试器在/处理程序中设置一个断点,然后通过一步代码跟踪Python所做的事情。
https://stackoverflow.com/questions/59597788
复制相似问题