谢谢
我创建了一个flask api,并将其作为docker镜像托管。该映像的dockerfile如下所示:
FROM pymesh/pymesh:latest
WORKDIR /apiapp
RUN pip install flask
EXPOSE 5000
COPY . /apiapp
ENV FLASK_APP=feature_extract_api.py
# ENTRYPOINT ['/bin/bash']
CMD ["flask", "run", "--host", "0.0.0.0"]
原始python文件中的app.run()
看起来像这样:
if __name__=='__main__':
app.run()
运行docker容器时的终端显示如下:
(dockerenv) D:SiemensDocker Pymesh API>docker run -p 5000:5000 pymeshapi:trial
* Serving Flask app 'feature_extract_api.py' (lazy loading)
* 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 all addresses.
WARNING: This is a development server. Do not use it in a production deployment.
* Running on http://172.17.0.2:5000/ (Press CTRL+C to quit)
然而,当我转到链接http://172.17.0.2:5000/时,我没有得到响应。但当我奔跑http://localhost:5000/,我得到一个有效的响应
为什么会发生这种情况?
谢谢
使用网桥网络IP地址的'技巧'在Windows上不起作用,这是由于它运行Docker的方式。
建议映射端口,使用localhost
。