# --------------------------------------------------------------
|
# Copyright (c) Microsoft Corporation. All rights reserved.
|
# Licensed under the MIT License.
|
# --------------------------------------------------------------
|
# Dockerfile to run ONNXRuntime with TensorRT integration
|
|
ARG BASEIMAGE=nvidia/cuda:12.8.1-cudnn-devel-ubuntu24.04
|
ARG TRT_VERSION=10.14.1.48-1+cuda12.9
|
ARG LD_LIBRARY_PATH_ARG=/usr/local/lib64:/usr/local/cuda/lib64
|
|
FROM $BASEIMAGE AS base
|
ARG TRT_VERSION
|
ARG LD_LIBRARY_PATH_ARG
|
ENV PATH=/usr/local/nvidia/bin:/usr/local/cuda/bin:/usr/src/tensorrt/bin:${PATH}
|
ENV DEBIAN_FRONTEND=noninteractive
|
|
ENV LD_LIBRARY_PATH=${LD_LIBRARY_PATH_ARG}${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
|
|
RUN apt-get update && \
|
apt-get install -y --no-install-recommends \
|
git \
|
bash \
|
wget \
|
diffutils \
|
python3 \
|
python3-pip \
|
python3-dev \
|
python3-wheel \
|
&& rm -rf /var/lib/apt/lists/*
|
|
# --- Fix for Ubuntu 24.04 (PEP 668) to allow global pip installs ---
|
RUN find /usr/lib/python3* -name "EXTERNALLY-MANAGED" -exec rm -f {} +
|
|
# Install TensorRT
|
RUN apt-get update && \
|
apt-get install -y \
|
libnvinfer-dev=${TRT_VERSION} \
|
libnvinfer-dispatch-dev=${TRT_VERSION} \
|
libnvinfer-dispatch10=${TRT_VERSION} \
|
libnvinfer-headers-dev=${TRT_VERSION} \
|
libnvinfer-headers-plugin-dev=${TRT_VERSION} \
|
libnvinfer-lean-dev=${TRT_VERSION} \
|
libnvinfer-lean10=${TRT_VERSION} \
|
libnvinfer-plugin-dev=${TRT_VERSION} \
|
libnvinfer-plugin10=${TRT_VERSION} \
|
libnvinfer-vc-plugin-dev=${TRT_VERSION} \
|
libnvinfer-vc-plugin10=${TRT_VERSION} \
|
libnvinfer10=${TRT_VERSION} \
|
libnvonnxparsers-dev=${TRT_VERSION} \
|
libnvonnxparsers10=${TRT_VERSION} \
|
tensorrt-dev=${TRT_VERSION} \
|
libnvinfer-bin=${TRT_VERSION} \
|
libnvinfer-headers-python-plugin-dev=${TRT_VERSION} \
|
libnvinfer-win-builder-resource10=${TRT_VERSION} && \
|
rm -rf /var/lib/apt/lists/*
|
|
COPY scripts /tmp/scripts
|
RUN cd /tmp/scripts && /tmp/scripts/install_dotnet.sh && rm -rf /tmp/scripts
|
|
# Build final image from base.
|
FROM base AS final
|
ARG BUILD_USER=onnxruntimedev
|
ARG BUILD_UID=1000
|
|
RUN if getent passwd $BUILD_UID > /dev/null; then \
|
echo "User with UID $BUILD_UID exists. Modifying." && \
|
EXISTING_USER=$(id -un $BUILD_UID) && \
|
EXISTING_GROUP=$(id -gn $EXISTING_USER) && \
|
usermod -l $BUILD_USER $EXISTING_USER && \
|
groupmod -n $BUILD_USER $EXISTING_GROUP && \
|
usermod -d /home/$BUILD_USER -m $BUILD_USER && \
|
chown -R $BUILD_USER:$BUILD_USER /home/$BUILD_USER; \
|
else \
|
echo "User with UID $BUILD_UID does not exist. Creating." && \
|
adduser --uid $BUILD_UID $BUILD_USER --disabled-password --gecos "ONNX Runtime Developer"; \
|
fi
|
# --- End of updated logic ---
|
|
WORKDIR /home/$BUILD_USER
|
USER $BUILD_USER
|