Dockerfile
FROM tensorflow/tensorflow:latest-py3-jupyter
# 设置工作空间为/app
WORKDIR /app
# 把当前目录下的文件拷贝到 容器里的/app里
ADD . /app
# 安装requirements.txt中指定的依赖
RUN pip install --no-cache=False --trusted-host pypi.python.org -r requirements.txt
# 开放5000端口
EXPOSE 5000 8888
# 设置 NAME 这个环境变量
ENV NAME World
#ENV http_proxy http://127.0.0.1:12333
#ENV https_proxy http://127.0.0.1:12333
# 当容器启动时,运行app.py
CMD ["python", "run_keras_server.py"]
requirements.txt
flask
numpy
keras
Pillow
gunicorn
gevent
/etc/default/docker
#修改文件/etc/default/docker,新增
export ALL_PROXY=socks5://127.0.0.1:1080
重启docker
sudo service docker stop
sudo service docker start
#docker 命令
docker build --network=host -t simple-keras .
docker run -d --name simple-keras --runtime=nvidia -v /home/reno/.keras:/root/.keras -v /home/reno/Github/jupyter:/tf/notebooks -p 8888:8888 -p 5000:5000 simple-keras:latest
flask
docker无法映射flask服务端口,从而访问127.0.0.1:5000的问题,需要在代码中注明地址0.0.0.0
# if this is the main thread of execution first load the model and
# then start the server
if __name__ == "__main__":
print(("* Loading Keras model and Flask starting server..."
"please wait until server has fully started"))
load_model()
app.run(host="0.0.0.0", debug=False, threaded=False)