簡體   English   中英

如何使用NVIDIA驅動程序/ CUDA(支持tensorflow-gpu)和帶pip的Python3為圖像制作Dockerfile?

[英]How to craft a Dockerfile for an image with NVIDIA driver/CUDA (support for tensorflow-gpu) and Python3 with pip?

使用包含以下內容的映像的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 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM