# Multi-stage build for Whisper Server (GPU-enabled) # This version includes CUDA support for NVIDIA GPUs with CPU fallback ARG CUDA_VERSION=12.3.1 ARG UBUNTU_VERSION=22.04 FROM nvidia/cuda:${CUDA_VERSION}-devel-ubuntu${UBUNTU_VERSION} AS builder # Set build arguments ARG WHISPER_VERSION=master ARG DEBIAN_FRONTEND=noninteractive ARG CUDA_DOCKER_ARCH=all # Set CUDA environment ENV CUDA_DOCKER_ARCH=${CUDA_DOCKER_ARCH} ENV GGML_CUDA=1 # Install build dependencies RUN apt-get update && apt-get install -y \ build-essential \ cmake \ git \ wget \ pkg-config \ libsdl2-dev \ && rm -rf /var/lib/apt/lists/* # Create working directory WORKDIR /app # Copy source code COPY whisper.cpp/ ./whisper.cpp/ # Build whisper server with CUDA support WORKDIR /app/whisper.cpp RUN cmake -B build \ -DCMAKE_BUILD_TYPE=Release \ -DWHISPER_BUILD_SERVER=ON \ -DWHISPER_BUILD_EXAMPLES=ON \ -DWHISPER_BUILD_TESTS=OFF \ -DBUILD_SHARED_LIBS=OFF \ -DGGML_STATIC=ON \ -DGGML_CUDA=ON \ -DGGML_NATIVE=OFF RUN cmake --build build --config Release --target whisper-server -j$(nproc) # Runtime stage - CUDA runtime image FROM nvidia/cuda:${CUDA_VERSION}-runtime-ubuntu${UBUNTU_VERSION} AS runtime # Set CUDA environment for runtime ARG CUDA_MAIN_VERSION=12.3 ENV CUDA_MAIN_VERSION=${CUDA_MAIN_VERSION} ENV LD_LIBRARY_PATH=/usr/local/cuda-${CUDA_MAIN_VERSION}/compat:$LD_LIBRARY_PATH # Install runtime dependencies RUN apt-get update && apt-get install -y \ curl \ ffmpeg \ ca-certificates \ && rm -rf /var/lib/apt/lists/* \ && apt-get clean # Create non-root user for security RUN useradd -m -u 1000 whisper && \ mkdir -p /app/models /app/uploads /app/public && \ chown -R whisper:whisper /app # Copy server binary and web interface COPY --from=builder /app/whisper.cpp/build/bin/whisper-server /app/ COPY --from=builder /app/whisper.cpp/examples/server/public/ /app/public/ # Copy entrypoint script COPY docker/entrypoint.sh /app/entrypoint.sh RUN chmod +x /app/entrypoint.sh && \ sed -i 's/\r$//' /app/entrypoint.sh # Set ownership RUN chown -R whisper:whisper /app # Switch to non-root user USER whisper WORKDIR /app # Expose server port EXPOSE 8178 # Health check HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \ CMD curl -f http://localhost:8178/ || exit 1 # Default environment variables ENV WHISPER_MODEL=models/ggml-base.en.bin ENV WHISPER_HOST=0.0.0.0 ENV WHISPER_PORT=8178 ENV WHISPER_THREADS=0 ENV WHISPER_USE_GPU=true # Set entrypoint ENTRYPOINT ["/app/entrypoint.sh"] CMD ["server"]