docker 环境配置 python 版
一. 配置对应的docker环境和nvidia-docker(注意加速镜像设置)
二. 环境配置
1. 拉取对应的镜像
docker pull nvidia/cuda:10.2-cudnn7-devel-ubuntu16.042. 制作数据卷
root@felaim-PC:~# docker run -v /home:/usr/Downloads --name dataVol nvidia/cuda:10.2-cudnn7-devel-ubuntu16.04 /bin/bash3. 制作自己的容器
不添加port
docker run -it --gpus all --name felaim_sever_ubuntu16.04_python --volumes-from dataVol nvidia/cuda:10.2-cudnn7-devel-ubuntu16.04 /bin/bash添加port
docker run -it --gpus all --name felaim_sever_ubuntu16.04_python --volumes-from dataVol -p 5594:5594 -p 5595:5595 -p 7022:22 nvidia/cuda:10.2-cudnn7-devel-ubuntu16.04 /bin/bash正确执行完之后,现在我们就处在新建的docker容器里了(端口映射,容器名,镜像和路径映射这些换成你自己的就行,但是一定要留一个端口映射到容器22端口,因为SFTP默认使用22端口)
4. 更新源和对应软件
apt-get update apt-get upgrade apt-get vim5. 安装anaconda
./Anaconda3-2019.07-Linux-x86_64.sh vim ~/.bashrc export PATH=$PATH:/root/anaconda3/bin source ~/.bashrc conda info6. 配置tensorflow python环境(tensorflow1.14_gpu)
conda create --name tensorflow1.14_gpu python=3.7 conda activate tensorflow1.14_gpu conda update -n base -c defaults conda conda install tensorflow-gpu=1.14.0 pip install opencv-python conda install jupyter notebook7. opencv 安装
pip install opencv-python8. 配置caffe 1.0
conda create -n caffe python=2.7 -c defaults conda update -n base -c defaults conda conda activate caffe conda install -c defaults caffe-gpu9. 配置onnx2caffe环境
conda create --name onnx2caffe python=3.7 # 版本需要根据镜像来自己设置 conda install pytorch==1.4.0 torchvision==0.5.0 cudatoolkit=10.0 -c pytorch conda install -c defaults caffe-gpu conda install -c conda-forge onnx10. 保存下对应的镜像
docker commit -a "felaim" -m "anaconda tensorflow1.14, caffe1.0" d3e39bd5be40 felaim_sever_ubuntu16.04_python:v0重新启动对应容器,并开放端口
docker run -it --gpus all --name felaim_sever_ubuntu16.04_python_v1 -p 5594:5594 -p 5595:5595 -p 7022:22 --volumes-from dataVol felaim_sever_ubuntu16.04_python:v0 /bin/bash正确执行完之后,现在我们就处在新建的docker容器里了(端口映射,容器名,镜像和路径映射这些换成你自己的就行,但是一定要留一个端口映射到容器22端口,因为SFTP默认使用22端口)
11. 配置SSH服务
apt-get update apt-get install -y openssh-server然后建立一个配置文件夹并进行必要的配置:
$ mkdir /var/run/sshd $ echo 'root:passwd' | chpasswd # 这里使用你自己想设置的用户名和密码,但是一定要记住! $ sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config $ sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd $ echo "export VISIBLE=now" >> /etc/profile重启SSH激活配置:
$ service ssh restart在服务器(宿主机)上(不是服务器的docker里)测试刚刚新建docker容器中哪个端口转发到了服务器的22端口:
$ sudo docker port [your_container_name] 22 # 如果前面的配置生效了,你会看到如下输出 # 0.0.0.0:7022最后测试能否用SSH连接到远程docker:
$ ssh root@[your_host_ip] -p 7022 # 密码是你前面自己设置的12. 配置jupyter notebbok
使用anaconda安装jupyter notebook
conda install jupyter notebook12.1 生成密码
在ubuntu的命令行里输入ipython打开ipython,(没有的话,输入python也可以)
ipython在python命令行里分别输入:
from notebook.auth import passwd passwd()会出现如下的密钥
In [1]: from notebook.auth import passwd In [2]: passwd() Enter password: Verify password: Out[2]: 'sha1:854d183417ac:db1e7***********************************' Out[2]: 'sha1:e2397bf86***********************************'这时候把sha1秘钥保存下来,然后退出ipython命令行:
quit12.2 生成jupyter notebook的配置文件
jupyter notebook --generate-config这时候会生成配置文件,在 ~/.jupyter/jupyter_notebook_config.py
12.3 配置文件
打开 ~/.jupyter/jupyter_notebook_config.py,加入一下内容:
sha1是之前生成的密钥
c.NotebookApp.ip='*' c.NotebookApp.password = u'sha1:854d183417ac:db1e783bde7bbab7**************************8' c.NotebookApp.open_browser = False c.NotebookApp.port =55955595表明要使用container的5595端口访问jupyter,然后保存退出。之前配置容器的时候开放的端口
12.4 打开jupyter notebook
jupyter notebook --allow-root(tensorflow1.14_gpu) root@5985394c021c:/usr/Downloads/felaim# jupyter notebook --allow-root [W 07:02:43.154 NotebookApp] WARNING: The notebook server is listening on all IP addresses and not using encryption. This is not recommended. [I 07:02:43.158 NotebookApp] Serving notebooks from local directory: /usr/Downloads/felaim [I 07:02:43.158 NotebookApp] The Jupyter Notebook is running at: [I 07:02:43.158 NotebookApp] http://5985394c021c:5595/最后改成0.0.0.0:5595就可以了
12.5 配置jupyter notebook
conda install nb_conda # 主题 pip install jupyterthemes jt -t onedork -f fira -fs 13 #自动补齐 python -m pip install jupyter_contrib_nbextensions jupyter contrib nbextension install --user --skip-running-check12. pytorch环境
三、新建一个docker caffe环境
root@felaim-PC:/home/felaim# docker run -it --gpus all --name caffe_gpu bvlc/caffe:gpu caffe --version Unable to find image 'bvlc/caffe:gpu' locally gpu: Pulling from bvlc/caffe 22dc81ace0ea: Pull complete 1a8b3c87dba3: Pull complete 91390a1c435a: Pull complete 07844b14977e: Pull complete b78396653dae: Pull complete 60e8c8e60650: Pull complete 60bcdd4a44b0: Pull complete 58b3ae962738: Pull complete 5217d046ef8d: Pull complete 8e4decdc2422: Pull complete 79b877e2a35a: Pull complete c2a456d945c3: Pull complete 3653aff6554b: Pull complete fd29b77c710b: Pull complete 9c27713c696a: Pull complete db5d7c50228c: Pull complete Digest: sha256:744c384e95f65494cd8ce7b560dcce9cb4c2f46b49792fe3cb0dba603ff20522 Status: Downloaded newer image for bvlc/caffe:gpu caffe version 1.0.0docker run -it --gpus all --name felaim_caffe --p 6022:22 --volumes-from dataVol felaim_sever_ubuntu16.04_python:v0 /bin/bash未完待续。。。