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

标签 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

针对上述尝试之一,我还可以尝试哪些其他方法或修复方法?

最佳答案

你可以使用这个:

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

关于python - 如何使用 NVIDIA 驱动程序/CUDA(支持tensorflow-gpu)和带有 pip 的 Python3 为图像制作 Dockerfile?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57351948/

相关文章:

bash - Dockerfile RUN 命令是否在登录 shell 环境中运行?

Docker:使用 dockerfile 在 Windows 容器上安装 chrome

python - 在 Python 中初始化全局变量的正确方法

python - 为什么 GridSearchCV 不给出最好的分数? - Scikit 学习

bash - 并发 az 登录执行

mysql - 无法使用纯数据容器创建 docker mysql

linux - 无法从同一局域网中的另一台主机 ping docker 容器

python - 创建 Google App Engine 数据存储区实体而不初始化特定属性

python - 如何在 OpenCV for Python 中使用冲浪和筛选检测器

amazon-web-services - 无法在 K8S 集群中使用图像(在 ECR 中)