Docker Community Forums

Share and learn in the Docker community.

How can I use two images in a single dockerfile

Hi all I’m learning docker using the documentation, I have a situation where I’m stuck, and any help on this would be great.

I have a Computer Vision model which is packaged as a microservice using Azure Functions but the model runs in a GPU machine. I have added the function app image but not sure how to add the Nvidia CUDA image to the dockerfile.

attaching my dockerfile code below

FROM mcr.microsoft.com/azure-functions/python:3.0-python3.8
ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
    AzureFunctionsJobHost__Logging__Console__IsEnabled=true

COPY requirements.txt /
RUN python -m venv .venv
RUN . .venv/bin/activate
RUN pip install -r /requirements.txt

COPY . /home/site/wwwroot

Nvidia image which I want to use is the below one

FROM nvidia/cuda:10.2-cudnn7-devel-ubuntu18.04

There is no option to inherit from two docker image, there can only be one base image.

You will have to pick on of the images as base images, and re-create the steps the other image has in its Dockerfile. If you only need some of the files of the 2nd image, you could leverage a multi stage build, prepare the artifacts (download, extract, build,… whatever is needed) and then use the COPY instruction with the --from=<name> argument to copy those files from the first stage into the final stage.