docker下最新搭建python3/cuda10(cudnn7.4)/tensorflow

0.install nvidia-docker

[260254@localhost ~]$ curl -s -L https://nvidia.github.io/nvidia-docker/centos7/x86_64/nvidia-docker.repo | sudo tee /etc/yum.repos.d/nvidia-docker.repo 
[260254@localhost ~]$ sudo yum search --showduplicates nvidia-docker
[260254@localhost ~]$ sudo yum install nvidia-docker2-2.0.3-1.docker18.09.2.ce.noarch

1.create container

docker run --name tf13 -it ubuntu /bin/bash

2.install python3.7.2、pip3

root@fd2df141e0b4:~/Python-3.7.2/build# apt -get install python-pip
root@fd2df141e0b4:~/Python-3.7.2/build# ./configure --prefix=/usr/local/python3

configure: error: no acceptable C compiler found in $PATH
apt-get install build-essential

可参考文章

root@fd2df141e0b4:~/Python-3.7.2/build#  nproc 
8
root@fd2df141e0b4:~/Python-3.7.2/build# make -j8 && make install -j8
root@fd2df141e0b4:~# apt-get install python3-pip
root@fd2df141e0b4:~# pip install opencv-python
root@fd2df141e0b4:~# pip3 install opencv-python

>>> import cv2
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/local/lib/python3.6/dist-packages/cv2/__init__.py", line 3, in 
    from .cv2 import *
ImportError: libSM.so.6: cannot open shared object file: No such file or directory

可参考文章

ImportError: libSM.so.6: cannot open shared object file: No such file or directory
ImportError: libXrender.so.1: cannot open shared object file: No such file or directory
ImportError: libXext.so.6: cannot open shared object file: No such file or directory
root@fd2df141e0b4:/# apt-get install libsm6 libxrender1 libxext6

3.inquire gpu

[260254@localhost ~]$ lspci | grep -i vga
01:00.0 VGA compatible controller: NVIDIA Corporation GM107GL [Quadro K620] (rev a2)
[260254@localhost ~]$ lspci -v -s 01:00.0
01:00.0 VGA compatible controller: NVIDIA Corporation GM107GL [Quadro K620] (rev a2) (prog-if 00 [VGA controller])
	Subsystem: NVIDIA Corporation Device 1098
	Physical Slot: 1
	Flags: bus master, fast devsel, latency 0, IRQ 125
	Memory at de000000 (32-bit, non-prefetchable) [size=16M]
	Memory at c0000000 (64-bit, prefetchable) [size=256M]
	Memory at d0000000 (64-bit, prefetchable) [size=32M]
	I/O ports at e000 [size=128]
	Expansion ROM at df000000 [disabled] [size=512K]
	Capabilities: 
	Kernel driver in use: nouveau
	Kernel modules: nouveau

4.install cuda(cudnn)

root@0d580c903134:~# apt-get update && apt-get install wget -y --no-install-recommends
root@0d580c903134:~# wget "http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-repo-ubuntu1804_10.0.130-1_amd64.deb"
root@0d580c903134:~# dpkg -i cuda-repo-ubuntu1804_10.0.130-1_amd64.deb
root@0d580c903134:~# apt-get install gnupg
root@0d580c903134:~# apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub
root@0d580c903134:~# apt-get update
root@0d580c903134:~# apt-get install cuda
root@0d580c903134:~# CUDNN_URL="http://developer.download.nvidia.com/compute/redist/cudnn/v7.4/cudnn-10.0-linux-x64-v7.4.2.24.tgz"
root@0d580c903134:~# wget ${CUDNN_URL}
root@0d580c903134:~# tar -xzf cudnn-10.0-linux-x64-v7.4.2.24.tgz -C /usr/local
root@0d580c903134:~# rm cudnn-10.0-linux-x64-v7.4.2.24.tgz && ldconfig

root@0d580c903134:/# cat /usr/local/cuda/version.txt 
CUDA Version 10.0.130
root@0d580c903134:/# cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2
#define CUDNN_MAJOR 7
#define CUDNN_MINOR 4
#define CUDNN_PATCHLEVEL 2
--
#define CUDNN_VERSION (CUDNN_MAJOR * 1000 + CUDNN_MINOR * 100 + CUDNN_PATCHLEVEL)
#include "driver_types.h"

5.install tensorflow

root@0d580c903134:~# pip install tensorflow-gpu

你可能感兴趣的:(Linux)