烧瓶服务虽然可以在docker外部运行,但无法通过docker端口运行

时间:2018-09-06 04:48:31

标签: docker flask

我正在使用Azure VM,并且正在使用端点文件key_matching_endpoint.py运行烧瓶服务

def log_request():
    _ = get_payload()
    pass

def labelify(query_by_words, label_dict):
    labels = []
    for word in query_by_words:
        def add_label():
            for label in label_dict:
                for word_list in label_dict[label]:
                    if word in word_list:
                        labels.append(label)
                        return
            labels.append('O')
        add_label()
    return ' '.join(labels)

def get_prediction():
    intent, pid, query, label_dict = get_payload()
    print("(intent, pid, query, label_dict):\n({0}, {1}, {2}, {3})".format(
        intent, pid, query, label_dict
    ))
    labels = labelify(query.split(' '), label_dict)
    print("labels:")
    print(labels)
    key_set = find_keys(in, pid, query, labels)
    # Here, we assume that only one product is given.
    return generate_response(intent, pid, ' '.join(label_dict['product'][0]), key_set)

############################################################
@app.route('/key_matcher', methods=["GET"])
def api():
    assert request.method == 'GET'
    print("*" * 50)
    log_request()
    return get_prediction()

############################################################
# HTTP Error Handlers
@app.errorhandler(404)
def url_error(e):
    return """
    Wrong URL!
    <pre>{0}</pre>""".format(e), 404

@app.errorhandler(500)
def server_error(e):
    return """
    An internal error occurred: <pre>{0}</pre>
    See logs for full stacktrace.
    """.format(e), 500

def main():
    app.run(host='0.0.0.0', debug=True)

当我通过tmux会话运行端点文件时

python key_matching_endpoint.py

端口9000已分配,我能够运行http://azure1.com:9000/key_matcher?in=prod&pid=109189474&query=vit

但是,当我从下面的Dockerfile进行构建时,构建Docker映像并公开端口5002时

FROM ubuntu:16.04
MAINTAINER Vivek Kaul "vkaul11@gmail.com"
#Install Ubuntu pkgs
COPY apt.conf /etc/apt/apt.conf
COPY . /product_info
WORKDIR /product_info
RUN apt-get update && apt-get install -y --no-install-recommends \
        ca-certificates \
        vim \
        git \
        python \
        python-pip \
        curl \
        wget \
        lsof \
        libmysqlclient-dev \
        python-dev \
        python-mysqldb \
        build-essential \
        && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

#PYTHON requirements

ENV HTTPS_PROXY "https://gec-proxy-svr.homeoffice.wal-mart.com:8080/"

RUN python --version
RUN pip install pip --upgrade
RUN pip install --upgrade setuptools
RUN pip install -r requirements.txt


EXPOSE 5002


RUN ls -la /product_info/key_matching/data

WORKDIR /product_info/key_matching

ENTRYPOINT ["python"]
CMD [ "key_matching_endpoint.py" ]

然后使用

docker run -p 5002:5002 product_info

我明白了

* Serving Flask app "key_matching_endpoint" (lazy loading)
 * Environment: production
   WARNING: Do not use the development server in a production environment.
   Use a production WSGI server instead.
 * Debug mode: on
 * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
 * Restarting with stat
 * Debugger is active!

现在http://azure1.com:5002/key_matcher?in=prod&pid=109189474&query=vit不起作用。我不知道如何准确地为烧瓶服务运行正确的端口。

0 个答案:

没有答案