Docker在成功创建并运行后未运行flask应用程序

时间:2018-02-01 01:22:02

标签: python machine-learning keras dockerfile

我无法让Docker在我的Flask应用程序上运行

  

我的烧瓶应用程序在本地成功运行,没有错误

     

基于我的dockerfile构建和运行docker容器时,我没有收到任何错误

Docker成功构建整个图像

Flask在本地成功运行

任何一端都没有显示错误

我正在将整个webapp复制到docker,它还具有所需的model.h5文件

我的dockerfile代码:

FROM python:3.5.3

# Grab requirements.txt.
ADD ./webapp/requirements.txt /tmp/requirements.txt

# Install dependencies
RUN pip install -qr /tmp/requirements.txt

# Add our code
ADD ./webapp /opt/webapp/
WORKDIR /opt/webapp

# ENTRYPOINT /bin/bash
EXPOSE 5000

ENTRYPOINT python ./app.py

我的烧瓶应用代码:

#!flask/bin/python
from keras.models import Sequential
from keras.layers.core import Flatten, Dense, Dropout
from keras.layers.convolutional import Convolution2D, MaxPooling2D, ZeroPadding2D
from keras.optimizers import SGD
from keras.preprocessing.image import load_img
from keras.preprocessing.image import img_to_array
from keras.applications.vgg16 import preprocess_input
from keras.applications.vgg16 import decode_predictions
from keras.models import load_model
from PIL import Image, ExifTags
from scipy.misc import imresize
from urllib.request import urlopen
import cv2, numpy as np
import io, traceback
import numpy as np
import tensorflow as tf
import requests
from flask import Flask
from flask import request
import pandas as pd
from sklearn import linear_model
import pickle

app = Flask(__name__)
print(" Loading vgg16 keras DNN model > ")
model = load_model('model.h5')
print(" Model loaded ")

@app.route('/')
def index():
    return " <h1> Flask is running </h1> "

@app.route('/predict', methods=['GET'])
def predict():
    my_var = request.args.get('my_var', None)

    def predictor(url):
        file = urlopen(url)
        image = load_img(file, target_size=(224, 224))
        image = img_to_array(image)
        image = image.reshape((1, image.shape[0], image.shape[1], image.shape[2]))
        image = preprocess_input(image)
        yhat = model.predict(image)
        label = decode_predictions(yhat)
        label = label[0][0]
        return('%s (%.2f%%)' % (label[1], label[2]*100))

    predicted_value = predictor(my_var)
    return str(predicted_value)


if __name__ == '__main__':
    app.run(port=5000,host='0.0.0.0')    

0 个答案:

没有答案