我构建了Flask应用程序,并试图使其在Docker文件上运行。
我运行两个命令:
1)
docker build -t my-api-docker:latest .
2)
docker run -p 5000:5000 my-api-docker
两者都运行无误,并且终端上的输出是经典的Flask:
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
如何
如果我访问:http://localhost:5000
如果表明:
页面无法正常工作
requirements.txt
Flask==1.1.1
requests==2.20.1
pandas==0.23.4
Dockerfile
FROM python:3.7
RUN pip install --upgrade pip
COPY ./requirements.txt /app/requirements.txt
WORKDIR /app
RUN pip install -r requirements.txt
COPY . /app
EXPOSE 5000
CMD [ "flask", "run" ]
答案 0 :(得分:2)
它不应与容器本地主机绑定,即
在http://127.0.0.1:5000/上运行(按CTRL + C退出)
更改Dockerfile中的CMD
CMD [ "flask", "run", "--host=0.0.0.0" ]
或
CMD ["python3", "-m", "flask", "run", "--host=0.0.0.0"]
或替换内部代码
app.run(host='0.0.0.0').