【发布时间】:2020-01-05 07:17:42
【问题描述】:
第一次使用 Docker(版本 19.03.5)并尝试这个tutorial
我被困在步骤 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,这可能会发生冲突,但不确定是否是这种情况和/或如何解决它。
【问题讨论】:
-
看起来你的烧瓶正在容器中运行,但是当你访问时(在 localhost:8888)它返回一个 500 错误。嗯,似乎错误是正确的 - 您的烧瓶应用程序可能有错误。尝试用您可以看到运行的最小应用程序替换您的烧瓶应用程序:flask.palletsprojects.com/en/1.1.x/quickstart/… 如果它运行正常, - 问题出在您的应用程序中。如果没有,则需要修复烧瓶应用程序的 docker 容器
-
@BrendaJ.Butler 我将 app.py 代码添加到我的帖子中
-
在 Docker 级别,如果您遇到 500 错误,一切都应该正常工作。应用程序日志应该有更多详细信息(如回溯),说明出了什么问题,您应该查看那里。
-
@DavidMaze 我如何获得回溯?我一直试图弄清楚如何在 Docker 中调试它,但没有成功。几个月前我确实在我的机器上安装了 WAMP,所以可能会出现冲突?
-
尝试将
COPY templates/index.html templates更改为COPY templates templates。 Flask 可能无法找到您的模板