如何使用NVIDIA驱动程序/ CUDA(支持tensorflow-gpu)和带pip的Python3为图像制作Dockerfile?

时间:2019-08-05 03:43:14

标签: python docker dockerfile nvidia nvidia-docker

使用包含以下内容的映像的Dockerfile创建Docker映像失败:

  1. Python3和pip,因此我可以使用pip安装我的Python应用程序的 包要求,然后可以访问Python3解释器 运行主要涉及Keras,TensorFlow和OpenCV的应用程序
  2. NVIDIA驱动程序和CUDA支持足以满足 TensorFlow在运行应用程序时利用GPU

我尝试用Dockerfile构建一个从Python基本映像开始的映像,并添加NVIDIA驱动程序,如下所示:

# minimal Python-enabled base image
FROM python:3.7

# add the NVIDIA driver
RUN apt-get update
RUN apt-get -y install software-properties-common
RUN add-apt-repository ppa:graphics-drivers/ppa
RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys FCAE110B1118213C
RUN apt-get update
RUN apt-get --yes install nvidia-driver-418

通过在上述Dockerfile上运行docker build,我得到了很多输出,但是最后,它给出了表明正在尝试安装我指定的更高驱动程序版本的消息(430,而不是418)。然后提示用户输入以设置键盘:

Building for architecture x86_64
Building initial module for 4.19.0-5-amd64
Error! Bad return status for module build on kernel: 4.19.0-5-amd64 (x86_64)
Consult /var/lib/dkms/nvidia/430.40/build/make.log for more information.
dpkg: error processing package nvidia-dkms-430 (--configure):
 installed nvidia-dkms-430 package post-installation script subprocess returned error exit status 10
Setting up xfonts-base (1:1.0.5) ...
Setting up libdrm2:amd64 (2.4.97-1) ...
dpkg: dependency problems prevent configuration of nvidia-driver-430:
 nvidia-driver-430 depends on nvidia-dkms-430 (= 430.40-0ubuntu0~gpu19.10.1); however:
  Package nvidia-dkms-430 is not configured yet.

dpkg: error processing package nvidia-driver-430 (--configure):
 dependency problems - leaving unconfigured
Setting up xauth (1:1.0.10-1) ...
Setting up xserver-common (2:1.20.4-1) ...
Setting up keyboard-configuration (1.191) ...
debconf: unable to initialize frontend: Dialog
debconf: (TERM is not set, so the dialog frontend is not usable.)
debconf: falling back to frontend: Readline
Configuring keyboard-configuration
----------------------------------

Please select the layout matching the keyboard for this machine.

  1. English (US)
  2. English (US) - Cherokee
  3. English (US) - English (Colemak)
  4. English (US) - English (Dvorak)
  5. English (US) - English (Dvorak, alt. intl.)
  6. English (US) - English (Dvorak, intl., with dead keys)
  7. English (US) - English (Dvorak, left-handed)
  8. English (US) - English (Dvorak, right-handed)
  9. English (US) - English (Macintosh)
  10. English (US) - English (US, alt. intl.)
  11. English (US) - English (US, euro on 5)
  12. English (US) - English (US, intl., with dead keys)
  13. English (US) - English (Workman)
  14. English (US) - English (Workman, intl., with dead keys)
  15. English (US) - English (classic Dvorak)
  16. English (US) - English (intl., with AltGr dead keys)
  17. English (US) - English (programmer Dvorak)
  18. English (US) - English (the divide/multiply keys toggle the layout)
  19. English (US) - Russian (US, phonetic)
  20. English (US) - Serbo-Croatian (US)
  21. Other
Keyboard layout: 

当我输入1时,所有内容似乎都挂起了,因此还无法正常工作。

我还尝试了以NVIDIA映像开头的Dockerfile,然后在其顶部添加Python和pip,如下所示:

FROM nvidia/driver:418.40.04-ubuntu18.04
RUN apt-get update
RUN apt-get -y install python3
RUN apt-get -y install python3-pip

使用以上命令运行docker build会出现此错误:

Step 4/8 : RUN apt-get -y install python3-pip
 ---> Running in eaa9a2ec71a9
Reading package lists...
Building dependency tree...
Reading state information...
E: Unable to locate package python3-pip
The command '/bin/sh -c apt-get -y install python3-pip' returned a non-zero code: 100

我可以尝试其他哪些方法或解决上述尝试之一?

1 个答案:

答案 0 :(得分:2)

您可以使用:

FROM nvidia/driver:418.40.04-ubuntu18.04
RUN apt-get -y update \
    && apt-get install -y software-properties-common \
    && apt-get -y update \
    && add-apt-repository universe
RUN apt-get -y update
RUN apt-get -y install python3
RUN apt-get -y install python3-pip
相关问题