Doocker ubuntu 16.04 学习总结(四)- 使用 docker搭建 Jupyter 环境 运行 handson_ml 机器学习程序

在学习 **Hands-on Machine Learning with Scikit-Learn and TensorFlow: ** 的过程中, 想创建一个可以随意变动的环境,在不同电脑上切换使用,不用每次安装, 于是将环境都装在 docker 中, 以供使用。 本博客只共记录自己的学习查找使用, 大神请勿在此浪费时间。

https://github.com/ageron/handson-ml

配置环境

  1. 生成 ubuntu/jupyter 镜像
$ docker pull ubuntu
$ docker run -i -t --name ubuntu_jupyter ubuntu /bin/bash
root@fa066f33e235:/# apt update
root@fa066f33e235:/#  apt install jupyter  # 安装 jupyter
root@fa066f33e235:/#  ctrl + c				  #  退出
  1. 保存 ubuntu/jupyter 镜像
$ docker commit ubuntu_jupyter ubuntu/jupyter # 将刚生成的container 储存为镜像
$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
ubuntu/jupyter      latest              65de65424d23        34 minutes ago      641MB
learn/ping          latest              82b6c745aa80        12 days ago         140MB
ubuntu              latest              94e814e2efa8        6 weeks ago         88.9MB
learn/tutorial      latest              a7876479f1aa        6 years ago         128MB

  1. 下载handson_ml 官方历程
    Hands-on Machine Learning with Scikit-Learn and TensorFlow 书中的历程在这里 https://github.com/ageron/handson-ml
$ git clone https://github.com/ageron/handson-ml.git  
$ docker run -i -t -p 8888:8888 -v /home/moi/Documents/handson-ml:/handson-ml --name handson_ml_jupyter ubuntu/jupyter  /bin/bash
			# -i 交互式; -t 打开终端; -p 将容器的8888 端口和 本机的8888 端口映射; 
			# -v 将本机的 handson-ml 映射到容器的 /handson-ml 目录下; --name 本容器的名字
root@fa066f33e235:/# ls
bin   dev  handson-ml  lib    media  opt   root  sbin  sys  usr
boot  etc  home        lib64  mnt    proc  run   srv   tmp  var
  1. 运行jupyter notebook 并运行 handson-ml 示例
root@fa066f33e235:/# jupyter notebook --allow-root --ip 0.0.0.0 --port=8888

本机打开
在这里插入图片描述
发现文件夹 handson-ml , 运行其中的文件
在这里插入图片描述

运行成功, 不过缺少一些依赖

  1. 新打开一个非同步窗口,安装必要的依赖

docker attach 进去的终端都是同步的, 我们需要新打开一个容器的终端

$ docker exec -i -t handson_ml_jupyter /bin/bash
root@fa066f33e235:/# pip3 install numpy
root@fa066f33e235:/# pip3 install matplotlib

运行成功,开启愉快的学习之旅
在这里插入图片描述

设置密码登录模式

执行完下面的命令直接, 设置密码就可以

$ jupyter notebook --generate-config
$ jupyter notebook password

在这里插入图片描述
设置成功!

									写于上海 至武汉的 G1720 高铁上!

在这里插入图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值