Docker 配置
- 安裝 docker
- 設置免 sudo 權限
- 下載 Ubuntu 鏡像
- 安裝 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
- 設置免 sudo 權限, 並重啓生效
~$ sudo groupadd docker
~$ sudo gpasswd -a ${USER} docker
~$ sudo service docker restart
~$ sudo reboot -h now
~$ service docker start
- 安裝 ubuntu 鏡像
~$ docker pull ubuntu
~$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu latest eb780ea9cf9e 5 weeks ago 69.4MB
創建容器 安裝 Jupyter
- 創建容器, 開放 80 端口
~$ docker run --name ubuntu_jupyter_test -p 8888:8888 -i -t ubuntu /bin/bash
- 安裝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
現在就可以正常使用鏡像了!