$ uname -a Linux CentOS 3.10.0-514.26.2.el7.x86_64 #1 SMP Tue Jul 4 15:04:05 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux $ cat /usr/local/cuda/version.txt CUDA Version 8.0.61 $ cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2 #define CUDNN_MAJOR 6 #define CUDNN_MINOR 0 #define CUDNN_PATCHLEVEL 21 #define CUDNN_VERSION (CUDNN_MAJOR * 1000 + CUDNN_MINOR * 100 + CUDNN_PATCHLEVEL) #include "driver_types.h" # NVIDIA 1080ti
$ ls -la /dev | grep nvidia crw-rw-rw- 1 root root 195, 0 Nov 15 13:41 nvidia0 crw-rw-rw- 1 root root 195, 1 Nov 15 13:41 nvidia1 crw-rw-rw- 1 root root 195, 255 Nov 15 13:41 nvidiactl crw-rw-rw- 1 root root 242, 0 Nov 15 13:41 nvidia-uvm crw-rw-rw- 1 root root 242, 1 Nov 15 13:41 nvidia-uvm-tools
電腦上裝了兩個顯卡。我須要運行pytorch,dockerhub中pytorch官方鏡像沒有gpu支持,因此只能先pull一個anaconda鏡像試試,後面能夠編排成Dockerfile。linux
$ docker run -it -d --rm --name pytorch -v /home/qiyafei/pytorch:/mnt/home --privileged=true --device /dev/nvidia-uvm:/dev/nvidia-uvm --device /dev/nvidia1:/dev/nvidia1 --device /dev/nvidiactl:/dev/nvidiactl okwrtdsh/anaconda3 bash
$ conda install pytorch torchvision -c pytorch
$ sudo rpm -i nvidia-docker-1.0.1-1.x86_64.rpm && rm nvidia-docker-1.0.1-1.x86_64.rpm $ sudo systemctl start nvidia-docker
$ docker pull nvidia/cuda $ nvidia-docker run --rm nvidia/cuda nvidia-smi
在容器內測試是能夠成功使用nvidia顯卡的:git
docker pull floydhub/pytorch:0.3.0-gpu.cuda8cudnn6-py3.22 nvidia-docker run -ti -d --rm floydhub/pytorch:0.3.0-gpu.cuda8cudnn6-py3.22 bash
deb-src http://archive.ubuntu.com/ubuntu xenial main restricted #Added by software-properties deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted multiverse universe #Added by software-properties deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted multiverse universe #Added by software-properties deb http://mirrors.aliyun.com/ubuntu/ xenial universe deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe deb http://mirrors.aliyun.com/ubuntu/ xenial multiverse deb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiverse deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse #Added by software-properties deb http://archive.canonical.com/ubuntu xenial partner deb-src http://archive.canonical.com/ubuntu xenial partner deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted multiverse universe #Added by software-properties deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe deb http://mirrors.aliyun.com/ubuntu/ xenial-security multiverse
$ vim Dockerfile
FROM nvidia/cuda LABEL author="qyf" ENV PYTHONIOENCODING=utf-8 RUN mv /etc/apt/sources.list /etc/apt/sources.list.bak ADD $PWD/sources.list /etc/apt/sources.list RUN apt-get update --fix-missing && \ apt-get install -y vim net-tools curl wget git bzip2 ca-certificates libglib2.0-0 libxext6 libsm6 libxrender1 mercurial subversion apt-transport-https software-properties-common RUN apt-get install -y openssh-server -y RUN echo 'root:passwd' | chpasswd RUN sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config RUN sed -i 's/#PasswordAuthentication yes/PasswordAuthentication yes/' /etc/ssh/sshd_config RUN echo 'export PATH=/opt/conda/bin:$PATH' > /etc/profile.d/conda.sh && wget --quiet https://repo.continuum.io/archive/Anaconda3-5.0.1-Linux-x86_64.sh -O ~/anaconda.sh && /bin/bash ~/anaconda.sh -b -p /opt/conda && rm ~/anaconda.sh ENV PATH /opt/conda/bin:$PATH RUN conda install pytorch torchvision -c pytorch -y ENTRYPOINT [ "/usr/bin/tini", "--" ] CMD [ "/bin/bash" ]
docker build -t pytorch/cuda8 ./