[docker]的使用

1 docker的安装

首先普及一下基本概念:docker是一个系统镜像管理器,可使用docker pull来下载网上已经打包好的特定环境的系统,这种系统称为image,将image拉下来以后,使用docker run进行运行,运行的系统实例称为容器(container)。由于docker能够封装任意环境的系统镜像,因此避免了复杂的环境配置,学习一些基本的docker命令可使用咱们作实验搭建环境事半功倍。
一些image须要nvidia-docker来pull,但nvidia-docker通用性差,因此咱们使用须要改成官方docker。
官方docker安装参考地址
官方docker安装后,使用先前须要配置环境,nvidia-docker替换为官方dockerpython

export CUDA_SO=$(\ls /usr/lib/x86_64-linux-gnu/libcuda.* | xargs -I{} echo '-v {}:{}')
export DEVICES=$(\ls /dev/nvidia* | xargs -I{} echo '--device {}:{}')

2 docker的使用

2.1 docker经常使用命令

pull系统镜像到本地linux

//下载theano系统镜像
docker pull kaixhin/cuda-theano:7.5
//下载tensorflow系统镜像
docker pull tensorflow/tensorflow:latest-gpu

建立一个名为theano的容器,将其文件系统中/work与本机中的’pwd’/theano目录进行关联,8000-9000做为对外开放的端口(尽可能少占用点端口),参考git

docker run --name xxx-theano -v `pwd`/theano:/work -w /work -itd -p 8000-9000:8000-9000 $CUDA_SO $DEVICES kaixhin/cuda-theano:7.5 bash

查看本地镜像与运行的容器github

docker images    // watch installed image 
docker ps -a     // watch image instances in docker

建立容器实例以后,还须要将容器与本地bash关联才能进入容器,以下docker

//将bash与theano容器进行attach,并运行该bash
docker exec –it theano bash

删除本地镜像或运行的容器shell

docker rm –vf theano	//删除名为theano的容器 
docker rm images_name	//删除名为imags_name的容器

2.2 局域网内用户直接登陆docker中某容器

docker中安装ssh:ubuntu

sudo apt-get install openssh-server

运行ssh/sshd或者用绝对路径( 有可能在/var/run/ssh中没有的话本身建立 )运行sshd
修改/etc/ssh/sshd_config,修改如下部分vim

port: 9020	//这个端口是运行docker run的时候留下的端口
Permitrootlogin:	yes

再启动sshwindows

sudo service ssh start	//启动ssh-server

以后就能够在xterm或者xshell中登陆了,注意端口要设置为sshd_config中留的端口号,如9020。
若是要使用户同时具备sudo权限bash

sudo usermod –aG sudo username

3.1 使用过程遇到的问题

(1) error: docker: Network timed out while trying to connect to xxx/images
You may want to check your internet connection or if you are behind a proxy.
solution:
sudo vim /etc/default/docker
a.在文件下方加入代理,由于默认为国外image源
b.加入DNS域名,具体域名内容参见windows系统中“ipv4 dns server”中的IP

DOCKER_OPTS="--dns 10.248.2.5 --dns 10.239.27.228 --dns 172.17.6.9"

c. 在本地docker server中添加本身为用户

sudo usermod -aG docker $USER

(2) error: Tag latest not found in repository docker.io/kaixhin/cuda-theano
由于tag中没有latest的名字,因此指名咱们要安装的具体版本:

docker pull kaixhin/cuda-theano:7.5

参考
(3) error: docker: unauthorized: authentication required
image pull 到一半时会提示该信息,而后以失败了结
solution:
查看系统时间信息时否正确,若是不正确在图形化界面中修改成当前时间

date

(4) error: cannot import name raise_from when python import theano

solution: pip --proxy http://child-prc.intel.com:913 install -U six

(5) 宿主机关机后
若是宿主机关机重启后,会发现docker ps –a中没有运行的容器,这时须要

docker start container

但有时候这句命令会报错:
dev/nvidia-uvm-tools: no such file or directory
Error: failed to start containers: caffe
解决

cd  /usr/local/cuda/samples/1_Utilities/deviceQuery
sudo ./deviceQuery
相关文章
相关标签/搜索