我创建了一个 python 包,它是一个 Flask 应用程序。我想在 Docker 容器中运行该应用程序。这是我的 Dockerfile:
FROM python:3.7
FROM pytorch/pytorch
MAINTAINER Nikolay Valkov nikolay1499@gmail.com
# set a directory for the app
WORKDIR /usr/app/
# copy all the files to the container
COPY . .
# install dependencies
RUN pip install --no-cache-dir -r requirements.txt
WORKDIR /usr/app/src/
RUN pip install -e .
WORKDIR /usr/app
# tell the port number the container should expose
EXPOSE 5000
ENV FLASK_APP packagename
# run the command
CMD flask run
我的应用程序绑定到 0.0.0.0,因此可以从 Docker 容器外部访问它,如下所示:
if __name__ == '__main__':
app.run(host='0.0.0.0')
如果需要该信息,则声明app.py并导入app 变量。__init__.py当我在没有 Docker 的情况下在本地运行 Flask 包时,一切正常,但是当我运行容器 localhost:5000 时,会出现 ERR_EMPTY_RESPONSE。我使用了命令docker run -p 5000:5000 nameofimage。有什么想法为什么会发生这种情况吗?我缺少什么?
编辑我被要求发布 python 代码: setup.py
from setuptools import setup
def readme():
with open("README.rst") as f:
return f.read()
setup(name = "generateme",
version = "0.1.2",
description = "Flask application to generate images with Generative Adversarial networks",
long_description = readme(),
url = "https://github.com/Nikolay1499/GenerateMe",
author = "Nikolay Valkov",
author_email = "nikolay1499@gmail.com",
license = "MIT",
packages = ["generateme"],
install_requires = [
"flask",
"gevent",
"numpy",
"Pillow",
"matplotlib",
"future",
],
zip_safe = False,
include_package_data = True,
)
__init__.py
from flask import Flask
import os
from generateme.app import app
from generateme.app import index, showImageConv, showImageLinear, showImageStyle
IMAGE_FOLDER = os.path.join("static", "Photos")
慕田峪4524236
慕标5832272
相关分类