multiarch accelerated base image
This commit is contained in:
@@ -1,155 +1,100 @@
|
|||||||
# Accelerated Base Image with Intel QuickSync, NVIDIA CUDA, FFmpeg, and Python support
|
# Multi-architecture accelerated base image with hardware encoding support
|
||||||
# Provides a comprehensive base for ML/CV applications with hardware acceleration
|
# Supports Intel QuickSync, NVIDIA CUDA, FFmpeg, and Python
|
||||||
FROM ubuntu:22.04
|
FROM ubuntu:22.04
|
||||||
|
|
||||||
LABEL maintainer="j"
|
|
||||||
LABEL description="Base image with Intel QuickSync, NVIDIA CUDA support, FFmpeg, and Python 3.11"
|
|
||||||
|
|
||||||
# Prevent interactive prompts during package installation
|
# Prevent interactive prompts during package installation
|
||||||
ENV DEBIAN_FRONTEND=noninteractive
|
ENV DEBIAN_FRONTEND=noninteractive
|
||||||
|
|
||||||
# Install system dependencies including Intel and NVIDIA support
|
# Install base dependencies and development tools
|
||||||
RUN apt-get update && apt-get install -y \
|
RUN apt-get update && apt-get install -y \
|
||||||
# Base utilities
|
# Basic tools
|
||||||
curl \
|
curl \
|
||||||
wget \
|
wget \
|
||||||
git \
|
git \
|
||||||
build-essential \
|
build-essential \
|
||||||
pkg-config \
|
pkg-config \
|
||||||
software-properties-common \
|
cmake \
|
||||||
# Python 3.11
|
# Python and pip
|
||||||
python3.11 \
|
python3 \
|
||||||
python3.11-dev \
|
|
||||||
python3-pip \
|
python3-pip \
|
||||||
python3.11-venv \
|
python3-dev \
|
||||||
# FFmpeg with hardware acceleration support
|
# Media libraries
|
||||||
ffmpeg \
|
libavcodec-dev \
|
||||||
# VAAPI dependencies (generic, works on both x86_64 and arm64)
|
libavformat-dev \
|
||||||
|
libavutil-dev \
|
||||||
|
libswscale-dev \
|
||||||
|
libavdevice-dev \
|
||||||
|
libavfilter-dev \
|
||||||
|
# Intel Media SDK dependencies (for QuickSync)
|
||||||
|
intel-media-va-driver-non-free \
|
||||||
vainfo \
|
vainfo \
|
||||||
libva-drm2 \
|
|
||||||
libva-dev \
|
libva-dev \
|
||||||
libva2 \
|
libva-drm2 \
|
||||||
# OpenGL/Graphics libraries
|
libva-x11-2 \
|
||||||
libgl1 \
|
# Additional libraries
|
||||||
libglib2.0-0 \
|
libglib2.0-0 \
|
||||||
libsm6 \
|
libsm6 \
|
||||||
libxext6 \
|
libxext6 \
|
||||||
libxrender-dev \
|
libxrender-dev \
|
||||||
libgomp1 \
|
libgomp1 \
|
||||||
libglu1-mesa \
|
# Clean up
|
||||||
libglu1-mesa-dev \
|
&& apt-get clean \
|
||||||
libgl1-mesa-dev \
|
|
||||||
libgl1-mesa-glx \
|
|
||||||
# OpenCV dependencies
|
|
||||||
libopencv-dev \
|
|
||||||
libgstreamer1.0-0 \
|
|
||||||
libgstreamer-plugins-base1.0-0 \
|
|
||||||
libgstreamer-plugins-bad1.0-0 \
|
|
||||||
gstreamer1.0-plugins-base \
|
|
||||||
gstreamer1.0-plugins-good \
|
|
||||||
gstreamer1.0-plugins-bad \
|
|
||||||
gstreamer1.0-plugins-ugly \
|
|
||||||
gstreamer1.0-libav \
|
|
||||||
gstreamer1.0-tools \
|
|
||||||
# Video codec libraries
|
|
||||||
libx264-dev \
|
|
||||||
libx265-dev \
|
|
||||||
libvpx-dev \
|
|
||||||
libfdk-aac-dev \
|
|
||||||
libmp3lame-dev \
|
|
||||||
libopus-dev \
|
|
||||||
# Image format libraries
|
|
||||||
libjpeg-dev \
|
|
||||||
libpng-dev \
|
|
||||||
libtiff-dev \
|
|
||||||
libwebp-dev \
|
|
||||||
# Additional ML/numeric libraries
|
|
||||||
libhdf5-dev \
|
|
||||||
libatlas-base-dev \
|
|
||||||
gfortran \
|
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
# Install architecture-specific Intel drivers (only on x86_64)
|
# Install FFmpeg with hardware acceleration support
|
||||||
RUN if [ "$(dpkg --print-architecture)" = "amd64" ]; then \
|
# Using static build for consistency across architectures
|
||||||
apt-get update && apt-get install -y \
|
RUN ARCH=$(uname -m) && \
|
||||||
intel-media-va-driver-non-free \
|
if [ "$ARCH" = "x86_64" ]; then \
|
||||||
i965-va-driver \
|
wget -q https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-linux64-gpl.tar.xz && \
|
||||||
&& rm -rf /var/lib/apt/lists/*; \
|
tar -xf ffmpeg-master-latest-linux64-gpl.tar.xz && \
|
||||||
|
mv ffmpeg-master-latest-linux64-gpl/bin/* /usr/local/bin/ && \
|
||||||
|
rm -rf ffmpeg-master-latest-linux64-gpl*; \
|
||||||
|
elif [ "$ARCH" = "aarch64" ]; then \
|
||||||
|
wget -q https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-linuxarm64-gpl.tar.xz && \
|
||||||
|
tar -xf ffmpeg-master-latest-linuxarm64-gpl.tar.xz && \
|
||||||
|
mv ffmpeg-master-latest-linuxarm64-gpl/bin/* /usr/local/bin/ && \
|
||||||
|
rm -rf ffmpeg-master-latest-linuxarm64-gpl*; \
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Set Python 3.11 as default
|
# Install NVIDIA CUDA support (will be ignored on non-NVIDIA systems)
|
||||||
RUN update-alternatives --install /usr/bin/python python /usr/bin/python3.11 1 && \
|
# Using a minimal CUDA runtime that works on both architectures
|
||||||
update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 1 && \
|
RUN ARCH=$(uname -m) && \
|
||||||
update-alternatives --install /usr/bin/pip pip /usr/bin/pip3 1
|
if [ "$ARCH" = "x86_64" ]; then \
|
||||||
|
apt-get update && \
|
||||||
|
apt-get install -y --no-install-recommends \
|
||||||
|
cuda-compat-11-8 \
|
||||||
|
libnvidia-encode-515 \
|
||||||
|
libnvidia-decode-515 \
|
||||||
|
|| echo "CUDA packages not available, skipping"; \
|
||||||
|
elif [ "$ARCH" = "aarch64" ]; then \
|
||||||
|
echo "ARM64 CUDA support will be provided by host system if available"; \
|
||||||
|
fi && \
|
||||||
|
apt-get clean && \
|
||||||
|
rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
# Upgrade pip and install essential Python packages
|
# Create non-root user for running applications
|
||||||
RUN python -m pip install --upgrade pip setuptools wheel
|
RUN useradd -m -s /bin/bash appuser
|
||||||
|
|
||||||
# Install core Python ML/CV packages (CPU versions by default)
|
# Set up Python environment
|
||||||
# CUDA versions can be overlaid at runtime or in derived images
|
RUN pip3 install --no-cache-dir --upgrade pip setuptools wheel
|
||||||
RUN pip install --no-cache-dir \
|
|
||||||
|
# Install commonly needed Python packages for media processing
|
||||||
|
RUN pip3 install --no-cache-dir \
|
||||||
numpy \
|
numpy \
|
||||||
scipy \
|
Pillow \
|
||||||
pandas \
|
|
||||||
matplotlib \
|
|
||||||
pillow \
|
|
||||||
opencv-python-headless \
|
opencv-python-headless \
|
||||||
scikit-learn \
|
imageio \
|
||||||
tqdm \
|
imageio-ffmpeg
|
||||||
pyyaml \
|
|
||||||
requests
|
|
||||||
|
|
||||||
# Install PyTorch CPU version (can be overridden in derived images for CUDA)
|
|
||||||
# Note: PyTorch provides different wheels for different architectures
|
|
||||||
RUN pip install --no-cache-dir \
|
|
||||||
torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
|
|
||||||
|
|
||||||
# Set environment variables for hardware acceleration
|
|
||||||
# VAAPI driver configuration (paths will be set at runtime via entrypoint)
|
|
||||||
|
|
||||||
# Python environment
|
|
||||||
ENV PYTHONUNBUFFERED=1
|
|
||||||
ENV PYTHONDONTWRITEBYTECODE=1
|
|
||||||
|
|
||||||
# OpenCV
|
|
||||||
ENV OPENCV_VIDEOIO_PRIORITY_GSTREAMER=1
|
|
||||||
|
|
||||||
# FFmpeg hardware acceleration preference
|
|
||||||
ENV FFMPEG_HWACCEL_PRIORITY="vaapi,cuda,auto"
|
|
||||||
|
|
||||||
# NVIDIA Container Toolkit environment variables (will be used if NVIDIA runtime is available)
|
|
||||||
ENV NVIDIA_VISIBLE_DEVICES=all
|
|
||||||
ENV NVIDIA_DRIVER_CAPABILITIES=compute,utility,video
|
|
||||||
|
|
||||||
# Create a non-root user for running applications
|
|
||||||
RUN useradd -m -s /bin/bash -u 1000 appuser && \
|
|
||||||
usermod -a -G video appuser
|
|
||||||
|
|
||||||
# Create common directories
|
|
||||||
RUN mkdir -p /app /data /models && \
|
|
||||||
chown -R appuser:appuser /app /data /models
|
|
||||||
|
|
||||||
# Create entrypoint script to set architecture-specific environment variables
|
|
||||||
RUN echo '#!/bin/bash\n\
|
|
||||||
export LIBVA_DRIVERS_PATH=/usr/lib/$(uname -m)-linux-gnu/dri\n\
|
|
||||||
if [ "$(uname -m)" = "x86_64" ]; then\n\
|
|
||||||
export LIBVA_DRIVER_NAME=iHD\n\
|
|
||||||
fi\n\
|
|
||||||
exec "$@"' > /entrypoint.sh && \
|
|
||||||
chmod +x /entrypoint.sh
|
|
||||||
|
|
||||||
# Set working directory
|
# Set working directory
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Health check command to verify Python and FFmpeg are working
|
# Switch to non-root user by default
|
||||||
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
|
||||||
CMD python -c "import torch, cv2, numpy; print('OK')" && ffmpeg -version > /dev/null 2>&1
|
|
||||||
|
|
||||||
# Default to non-root user (can be overridden in derived images)
|
|
||||||
USER appuser
|
USER appuser
|
||||||
|
|
||||||
# Set entrypoint
|
# Set environment variables for hardware acceleration
|
||||||
ENTRYPOINT ["/entrypoint.sh"]
|
ENV LIBVA_DRIVER_NAME=iHD
|
||||||
|
ENV LIBVA_DRIVERS_PATH=/usr/lib/x86_64-linux-gnu/dri
|
||||||
|
|
||||||
# Default command - can be overridden in derived images
|
# Default command
|
||||||
CMD ["/bin/bash"]
|
CMD ["/bin/bash"]
|
Reference in New Issue
Block a user