【发布时间】:2021-04-17 13:16:04
【问题描述】:
我正在使用python:3.7.4-slim-buster docker 映像,但我无法更改它。
我想知道如何在上面使用我的 nvidia gpus。
我通常使用tensorflow/tensorflow:1.14.0-gpu-py3 和一个简单的--runtime=nvidia int docker run 命令一切正常,但现在我有这个限制。
我认为这种类型的图像不存在快捷方式,因此我遵循本指南 https://towardsdatascience.com/how-to-properly-use-the-gpu-within-a-docker-container-4c699c78c6d1,构建它建议的 Dockerfile:
FROM python:3.7.4-slim-buster
RUN apt-get update && apt-get install -y build-essential
RUN apt-get --purge remove -y nvidia*
ADD ./Downloads/nvidia_installers /tmp/nvidia > Get the install files you used to install CUDA and the NVIDIA drivers on your host
RUN /tmp/nvidia/NVIDIA-Linux-x86_64-331.62.run -s -N --no-kernel-module > Install the driver.
RUN rm -rf /tmp/selfgz7 > For some reason the driver installer left temp files when used during a docker build (i dont have any explanation why) and the CUDA installer will fail if there still there so we delete them.
RUN /tmp/nvidia/cuda-linux64-rel-6.0.37-18176142.run -noprompt > CUDA driver installer.
RUN /tmp/nvidia/cuda-samples-linux-6.0.37-18176142.run -noprompt -cudaprefix=/usr/local/cuda-6.0 > CUDA samples comment if you dont want them.
RUN export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib64 > Add CUDA library into your PATH
RUN touch /etc/ld.so.conf.d/cuda.conf > Update the ld.so.conf.d directory
RUN rm -rf /temp/* > Delete installer files.
但它会引发错误:
ADD failed: stat /var/lib/docker/tmp/docker-builder080208872/Downloads/nvidia_installers: no such file or directory
我可以改变什么来轻松地让 docker 镜像看到我的 gpus?
【问题讨论】:
-
将您的 Dockerfile 建立在 nvidia-docker image 上。您需要在主机上安装 cuda 驱动程序。
-
你不能改变
python:3.7.4-slim-buster,因为你需要这个特定的python版本,对吧? -
@anemyte 是的,至少我不应该使用 tensorflow/pytorch 图像。最好保留这个。为什么?你有什么想法吗?
-
我有一个基于 Ubuntu 的带有 python3.7 和 CUDA 的 Dockerfile。我用它来为我的需要创建一个自定义的 Tensorflow 图像。如果这符合您的需求,我会将其作为答案发布。
-
@sim 谢谢你。你能给我一个 Dockerfile 示例来保持我的图像不变吗?
标签: python docker dockerfile gpu nvidia