Dean Schulze
Dean Schulze

Reputation: 10303

How do I get an nvidia driver in my docker ubuntu image?

I need to run a cuda binary on kubernetes. I've set up the nodes to use the kubernetes nvidia device plugin with nvidia-docker2. Here is my Dockerfile:

FROM ubuntu:18.04
COPY addarrays /addarrays
ENTRYPOINT [ "/addarrays" ]

When I run the docker image through nvidia-docker2 or kubernetes it gives this error:

Cuda failure addarrays.cu:9: 'CUDA driver version is insufficient for CUDA runtime version' 
Cuda failure addarrays.cu:9: 'CUDA driver version is insufficient for CUDA runtime version' 
Cuda failure addarrays.cu:9: 'CUDA driver version is insufficient for CUDA runtime version' 
Cuda failure addarrays.cu:9: 'CUDA driver version is insufficient for CUDA runtime version' 
Cuda failure addarrays.cu:9: 'CUDA driver version is insufficient for CUDA runtime version' 
Cuda failure addarrays.cu:9: 'CUDA driver version is insufficient for CUDA runtime version' 
addarrays: addarrays.cu:62: int main(): Assertion `hostArrayTmp[i] == hostArrayDest[i]' failed.

It looks like my docker image needs an nvidia driver. I've modified the Dockerfile like this:

FROM ubuntu:18.04
RUN apt install software-properties-common
RUN add-apt-repository ppa:graphics-drivers
RUN apt update
RUN apt install nvidia-driver-440
COPY addarrays /addarrays
ENTRYPOINT [ "/addarrays" ]

The software-properties-common is needed to install add-apt-repository, but it fails with this message:

E: Unable to locate package software-properties-common

What do I need to do to get an nvidia driver installed in my docker image?

Upvotes: 1

Views: 8485

Answers (1)

Chris
Chris

Reputation: 5673

You have to do the apt update first. On install commands you should use the -y flag. Also you should concatenate the commands into a single run command.

FROM ubuntu:18.04

RUN apt update && \
    apt install software-properties-common -y && \
    add-apt-repository ppa:graphics-drivers && \
    apt install nvidia-driver-440 -y

COPY addarrays /addarrays

ENTRYPOINT [ "/addarrays" ]

Upvotes: 4

Related Questions