Doocker ubuntu 16.04 学习总结(三)- 在Resberry Pi 上 使用 docker搭建 Jupyter 环境

Docker 配置

  • 安装 docker
  • 设置免 sudo 权限
  • 下载 Ubuntu 镜像
  1. 安装 docker
~$ sudo apt-get update
~$ sudo apt install docker.io
$ docker version 
Client:
 Version:           18.09.2
 API version:       1.39
 Go version:        go1.10.4
 Git commit:        6247962
 Built:             Tue Feb 26 23:55:10 2019
 OS/Arch:           linux/arm
 Experimental:      false

Server:
 Engine:
  Version:          18.09.2
  API version:      1.39 (minimum version 1.12)
  Go version:       go1.10.4
  Git commit:       6247962
  Built:            Tue Feb 12 22:47:29 2019
  OS/Arch:          linux/arm
  Experimental:     false

  1. 设置免 sudo 权限, 并重启生效
~$ sudo groupadd docker
~$ sudo gpasswd -a ${USER} docker
~$ sudo service docker restart
~$ sudo reboot -h now
~$ service docker start
  1. 安装 ubuntu 镜像
~$ docker pull ubuntu
~$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
ubuntu              latest              eb780ea9cf9e        5 weeks ago         69.4MB

创建容器 安装 Jupyter

  1. 创建容器, 开放 80 端口
~$ docker run --name ubuntu_jupyter_test -p 8888:8888 -i -t ubuntu /bin/bash
  1. 安装python3 / Jupyter
root@c71d3bbe36de:/# apt-get update
root@c71d3bbe36de:/# apt install jupyter

运行 Jupyter 网络环境

jupyter-notebook 启动jupyter
–no-browser 不在docker 内启动浏览器
–ip 0.0.0.0 服务的ip地址
–port=8888 服务的端口

root@81e9b34514b1:/# jupyter notebook --no-browser --ip 0.0.0.0 --port=8888 --allow-root
[I 18:14:48.511 NotebookApp] Serving notebooks from local directory: /
[I 18:14:48.511 NotebookApp] 0 active kernels
[I 18:14:48.511 NotebookApp] The Jupyter Notebook is running at:
[I 18:14:48.511 NotebookApp] http://0.0.0.0:8888/?token=2fb9ee68b373f09b02c84a4c0a5dd39b203fa4189208fdcf
[I 18:14:48.511 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 18:14:48.511 NotebookApp] 
    
    Copy/paste this URL into your browser when you connect for the first time,
    to login with a token:
        http://0.0.0.0:8888/?token=2fb9ee68b373f09b02c84a4c0a5dd39b203fa4189208fdcf

在最后有一个 token = 2fb9ee68b373f09b02c84a4c0a5dd39b203fa4189208fdcf, 复制下来填入浏览器页面;

打开浏览器, 输入地址 http://127.0.0.1:8888 , 因为主机的端口8888 已经映射到了 docker 内的 8888 端口,所以请求将转到 docker 内的 8888 端口

在这里插入图片描述运行成功
在这里插入图片描述现在可以直接在这里来查看和编写执行文件了!

docker的 save/load 与 export/import应用

镜像的存储 commit 与使用
将配置好的 container 存储成新的镜像

~$ docker commit ubuntu_jupyter_test ubuntu/jupyter
~$ docker images // 检查镜像是否生成成功
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
ubuntu/jupyter      latest              89381f9e0db6        7 seconds ago       641MB
ubuntu              latest              94e814e2efa8        5 weeks ago         88.9MB

使用利用 image生成 新的 容器, 此时容器内 jupyter 已经安好

~$ docker run -i -t -p 8889:8889 --name ubuntu_jupyter_test2 ubuntu/jupyter /bin/bash
root@d467d5356c6b:/#jupyter
usage: jupyter [-h] [--version] [--config-dir] [--data-dir] [--runtime-dir]
              [--paths] [--json]
              [subcommand] 

镜像打包与加载

打包 save

$ docker save ubuntu/jupyter -o ./docker_img/ubuntu_jupyter.tar

加载 load

$ docker load -i  ubuntu/jupyter -o ./docker_img/ubuntu_jupyter.tar
Loaded image: ubuntu/jupyter:latest

现在就可以正常使用镜像了!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章