Docker与anaconda+jupyter

Arch docker的安装

//pacman 安装docker
 sudo pacman -S docker
//docker启动
 sudo systemctl start docker
//设置开机启动docker
 sudo systemctl enable docker
//将用户添加到docker组
 sudo gpasswd -a [usr] docker
//docker 常用命令
 docker info
 docker images
 docker ps
 docker -h

docker进行配置

//解决docker pull timeout
 sudo vi /etc/docker/daemon.json  
//添加
{
  "registry-mirrors": ["https://docker.mirrors.ustc.edu.cn"]
}
//拉取ubuntu到本地
 sudo docker pull ubuntu
//查看本地的镜像
 sudo docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
hello-world         latest              fce289e99eb9        2 weeks ago         1.84kB
ubuntu              latest              1d9c17228a9e        2 weeks ago         86.7MB
//运行镜像,创建一个容器 :
//-p 将本地端口的9900映射到容器端口的8888 
//  -v 将本地目录/root/JupyterNotebook挂载到容器的/JupyterNotebook 也可以不需要
 sudo docker run -it -p 9900:8888 -v /root/JupyterNotebook:/JupyterNotebook 1d9c17228a9e  /bin/bash
//这时就已经进入容器了
 root@1912314cf2b6:/# 
//更新源
 root@1912314cf2b6:/# apt-get update
//安装wget下载anaconda
 root@1912314cf2b6:/# wget https://repo.anaconda.com/archive/Anaconda3-2018.12-Linux-x86_64.sh
//运行脚本,一路回车按照提示就行
 root@1912314cf2b6:/# bash Anaconda3-2018.12-Linux-x86_64.sh
//source一下bash
 root@1912314cf2b6:/# source /root/.bashrc root@1912314cf2b6:/# rm -rf Anaconda3-2018.12-Linux-x86_64.sh

jupyter Notebook配置

//生成配置文件
 root@1912314cf2b6:/# jupyter notebook --generate-config
//生成密钥
 root@1912314cf2b6:/# ipython
 Python 3.7.0 (default, Jun 28 2018, 13:15:42)
 Type 'copyright', 'credits' or 'license' for more information
 IPython 6.5.0 -- An enhanced Interactive Python. Type '?' for help.

 In [1]: from notebook.auth import passwd
 In [2]: passwd()
 Enter password:
 Verify password:
 Out[2]: 'sha1:4e379475fe85:e9aee4f0b42202fee4f14be37ee8b29ae7dad126'
 In [3]: exit()
//'sha1:4e379475fe85:e9aee4f0b42202fee4f14be37ee8b29ae7dad126'这个东西会写到配置文件里复制下来
//编辑配置文件
 root@1912314cf2b6:/# vi  /root/.jupyter/jupyter_notebook_config.py
//在文件末尾写入(如果后面有需要,看文档就好了)
c.NotebookApp.ip='*'                       # 设置所有ip可以访问
c.NotebookApp.password = u'sha:ce...       # 刚才复制的那个密文'
c.NotebookApp.open_browser = False         # 禁止自动打开浏览器
c.NotebookApp.port =8888                   #指定打开的端口

//这里写一个脚本用来启动jupyter notebook
//进入容器
 docker exec -it ubuntu /bin/bash
 root@1912314cf2b6:/# vim notebook.sh
#!/bin/bash
#!/root/.bashrc
/root/anaconda3/bin/jupyter notebook --allow-root

docker exec -d blissful_blackwell /notebook.sh
//使用Jupyter Notebook
 root@1912314cf2b6:/# jupyter notebook --allow-root
[I 08:47:49.861 NotebookApp] Writing notebook server cookie secret to /root/.local/share/jupyter/runtime/notebook_cookie_secret[W 08:47:50.071 NotebookApp] WARNING: The notebook server is listening on all IP addresses and not using encryption. This is not recommended.
[I 08:47:50.113 NotebookApp] JupyterLab extension loaded from /root/anaconda3/lib/python3.7/site-packages/jupyterlab[I 08:47:50.113 NotebookApp] JupyterLab application directory is /root/anaconda3/share/jupyter/lab[I 08:47:50.118 NotebookApp] Serving notebooks from local directory: /[I 08:47:50.118 NotebookApp] The Jupyter Notebook is running at:
[I 08:47:50.118 NotebookApp] http://(eb0788fc375d or 127.0.0.1):8888/[I 08:47:50.118 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).

//如果访问不了的话,就是主机的端口还没有打开(可以使用telnet来测试你的端口是否允许访问)
 iptables -I INPUT -p tcp --dport 9900 -m state --state NEW -j ACCEPT
 iptables-save > /etc/sysconfig/iptables
 reboot

 docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                         PORTS                    NAMESroot@eb0788fc375d:/# 
eb0788fc375d        cd6d8154f1e1        "/bin/bash"         46 minutes ago      Up 42 seconds                  0.0.0.0:9900->8888/tcp   blissful_blackwell

结束

最后用docker commit 提交更新image

Avatar
Ryan
Self Driving Car Engineer
下一页
上一页