从0开始构建jupyter+tensorflow+keras的docker镜像

趁热记录下,给未来的自己

前言

最近在学习机器学习,为了方便在不同地方可以访问到相同的学习资源和保证学习进度的连续性以及无需重复搭建环境,从而降低学习成本,就需要搭建一套在线的学习平台,保证在任何地方,都可以快速进入学习状态。借助于jupyter可以完美满足我的需求。

另外,考虑到移植的方便性,将采用docker的方式构建和部署平台。

Dockerfile

注意:Dockerfile需要和sources.list在同一个目录下

FROM rackspacedot/python37
MAINTAINER: arkMon
RUN mv /etc/apt/sources.list /etc/apt/sources.list.bak
COPY ./sources.list /etc/apt/
RUN apt-get update & apt-get upgrade -y
RUN pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/ # 更新pip源
RUN /usr/local/bin/python -m pip install --upgrade pip # 更新pip
RUN pip3 install matplotlib # 安装python画图插件
RUN pip3 install jupyter # 安装jupyter
RUN ipython3 kernel install
RUN pip3 install ipywidgets # 安装Jupyter交互界面扩展组件
RUN jupyter nbextension enable --py widgetsnbextension # 安装Jupyter交互界面扩展组件
RUN echo "c.NotebookApp.open_browser = False" >> /root/.jupyter/jupyter_notebook_config.py # 配置Jupyter远程访问
RUN echo "c.NotebookApp.notebook_dir = '/root/jupyter'" >> /root/.jupyter/jupyter_notebook_config.py # 配置Jupyter远程访问
RUN echo "c.NotebookApp.ip = '*'" >> /root/.jupyter/jupyter_notebook_config.py # 配置Jupyter远程访问
# 安装tensorflow
RUN pip3 install --upgrade tensorflow
RUN pip3 install tensorflow
# 安装keras
RUN pip3 install keras
# 启动容器时命令
CMD jupyter notebook --allow-root
复制代码

$ cat sources.list

deb http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
复制代码

构建镜像

$ docker build .

注意:该命令的运行目录和Dockerfile必须在同一层目录下

启动镜像

$ docker run -dti --name jupyter_keras -p 40000:8888 -v /data/workspace/docker-install/keras_jupyter/jupyter:/root/jupyter ${image_id}

把容器内的 /root/jupyter
目录挂载到宿主机 /data/workspace/docker-install/keras_jupyter/jupyter
目录下,后续可以做负载均衡的横向扩展

外部访问

地址:http://宿主机IP:40000

稀土掘金
我还没有学会写个人说明!
上一篇

法拉第未来FF在珠海成立新公司,注册资本2.5亿美元

下一篇

App 启动提速实践和一些想法

你也可能喜欢

评论已经被关闭。

插入图片