1

I have to bundle up my system using Docker. But my system uses Java (JAR file to run) and python with PyTorch. I initially tried to use openjdk:buster base Docker image and then installed python3 on top of it. So both JAR and PyTorch worked, but PyTorch is only CPU supportive. But now I have to speed-up my PyTorch code using GPU, and for that I need NVIDIA-Cuda. In a separate Docker, I found nvidia/cuda:10.2-base-ubuntu18.04 works for my PyTorch. But this Docker can't run JAR file.

So I am stuck in combining these 2. I either want to

  1. install NVIDIA-Cuda dependencies to openjdk Docker base image
  2. install openjdk (openjdk-14) dependencies to NVIDIA-Cuda Docker base image

Anyone has any suggestions on how I can do that or any alternative hacks ?

1 Answers1

2

You can have a single image, instead of two by creating your own docker image that uses the nvidia image, and install java on it. I.e. have a Dockerfile as below

FROM nvidia/cuda:10.2-base-ubuntu18.04

RUN apt-get update
RUN apt-get install openjdk-14-jdk

COPY <your jar file> <a path>
CMD [ "java" "other java flags/args>" "-jar" "<path to your jar file>"]

run docker build on that Dockerfile, and docker run as you normally would, and your java code should have access to NVIDIA-Cuda. (Also note, some prefer ENTRYPOINT to CMD)

Pickled Brain
  • 313
  • 1
  • 6