驱动 >=560.35.05
PyTorch 2.9.1 + CUDA 12.6
生成经过验证的生产级 Dockerfile 配置
配置摘要
框架
PyTorch 2.9.1
CUDA 版本
12.6
Python 支持
3.10, 3.11, 3.12
最低驱动
>=560.35.05
说明: 稳定生产环境,适合Hopper/Ampere架构
PyTorch 2.9.1 新特性
- 官方 CUDA 12.8 (cu128) 编译包,Blackwell (10.0) 原生支持
- 支持 Python 3.10-3.12(弃用 3.9)
- 增强 Hopper (H100/H200) 和 Blackwell (B200/GB200) 架构优化
- cuDNN 9.x 性能优化配合 Ubuntu 24.04
- 改进的 torch.compile() 和 inductor 编译器
- 增强的 FlexAttention API,支持高效自定义注意力
性能: 在 Blackwell GPU 上性能比 PyTorch 2.4 提升最多 3 倍
需要 Python 3.10+,不再支持 Python 3.9
最佳用途
适用场景
- Blackwell B200/GB200 GPU 部署(2025年最新硬件)
- Hopper H100/H200 生产级推理和训练
- 现代 Python 3.11/3.12 环境配合 Ubuntu 24.04
- 需要 CUDA 12.8 最高性能的 LLM 推理
CUDA 12.6 优势
- Hopper/Ampere 架构的稳定生产环境
- Ubuntu 22.04 部署,经过验证的稳定性
- 驱动不满足 12.8 要求时的替代方案
限制: 无 Blackwell 原生支持,B200/GB200 建议使用 12.8
生成 Dockerfile
配置选项
本地 GPU 或 CPU 环境
稳定生产环境,适合Hopper/Ampere架构
需要 NVIDIA 驱动版本 >=560.35.05
Dockerfile
1# syntax=docker/dockerfile:12# ^ Required for BuildKit cache mounts and advanced features34# Generated by DockerFit (https://tools.eastondev.com/docker)5# PYTORCH 2.9.1 + CUDA 12.6 | Python 3.116# Multi-stage build for optimized image size78# ==============================================================================9# Stage 1: Builder - Install dependencies and compile10# ==============================================================================11FROM nvidia/cuda:12.6.3-cudnn-devel-ubuntu22.04 AS builder1213# Build arguments14ARG DEBIAN_FRONTEND=noninteractive1516# Environment variables17ENV PYTHONUNBUFFERED=118ENV PYTHONDONTWRITEBYTECODE=119ENV TORCH_CUDA_ARCH_LIST="8.0;8.6;8.9;9.0"2021# Install Python 3.11 from deadsnakes PPA (Ubuntu 22.04)22RUN apt-get update && apt-get install -y --no-install-recommends \23 software-properties-common \24 && add-apt-repository -y ppa:deadsnakes/ppa \25 && apt-get update && apt-get install -y --no-install-recommends \26 python3.11 \27 python3.11-venv \28 python3.11-dev \29 build-essential \30 git31 && rm -rf /var/lib/apt/lists/*3233# Create virtual environment34ENV VIRTUAL_ENV=/opt/venv35RUN python3.11 -m venv $VIRTUAL_ENV36ENV PATH="$VIRTUAL_ENV/bin:$PATH"3738# Upgrade pip39RUN pip install --no-cache-dir --upgrade pip setuptools wheel4041# Install PyTorch with BuildKit cache42RUN --mount=type=cache,target=/root/.cache/pip \43 pip install torch torchvision torchaudio \44 --index-url https://download.pytorch.org/whl/cu1264546# Install project dependencies47COPY requirements.txt .48RUN --mount=type=cache,target=/root/.cache/pip \49 pip install -r requirements.txt5051# ==============================================================================52# Stage 2: Runtime - Minimal production image53# ==============================================================================54FROM nvidia/cuda:12.6.3-cudnn-runtime-ubuntu22.04 AS runtime5556# Labels57LABEL maintainer="Generated by DockerFit"58LABEL version="2.9.1"59LABEL description="PYTORCH 2.9.1 + CUDA 12.6"6061# Environment variables62ENV PYTHONUNBUFFERED=163ENV PYTHONDONTWRITEBYTECODE=164ENV NVIDIA_VISIBLE_DEVICES=all65ENV NVIDIA_DRIVER_CAPABILITIES=compute,utility6667# Install Python 3.11 runtime from deadsnakes PPA (Ubuntu 22.04)68RUN apt-get update && apt-get install -y --no-install-recommends \69 software-properties-common \70 && add-apt-repository -y ppa:deadsnakes/ppa \71 && apt-get update && apt-get install -y --no-install-recommends \72 python3.11 \73 libgomp174 && apt-get remove -y software-properties-common \75 && apt-get autoremove -y \76 && rm -rf /var/lib/apt/lists/*7778# Create non-root user for security79ARG USERNAME=appuser80ARG USER_UID=100081ARG USER_GID=$USER_UID82RUN groupadd --gid $USER_GID $USERNAME \83 && useradd --uid $USER_UID --gid $USER_GID -m $USERNAME8485# Copy virtual environment from builder86COPY --from=builder --chown=$USERNAME:$USERNAME /opt/venv /opt/venv87ENV VIRTUAL_ENV=/opt/venv88ENV PATH="$VIRTUAL_ENV/bin:$PATH"8990# Set working directory91WORKDIR /app9293# Copy application code94COPY --chown=$USERNAME:$USERNAME . .9596# Switch to non-root user97USER $USERNAME9899# Expose port100EXPOSE 8000101102# Default command103CMD ["python", "main.py"]
🚀 推荐部署
高性能 GPU 与 AI 云服务器
为您的 Docker 容器提供强大的 NVIDIA 算力支持,支持 A100/H100,全球 32 个机房可选。
- 支持 NVIDIA A100/H100 GPU 实例
- 按小时计费,测试成本低至 $0.004/h
- 全球 32+ 数据中心,极低访问延迟
- 一键运行容器化应用与裸金属服务器
常见问题
需要什么版本的 NVIDIA 驱动?
PyTorch 2.9.1 + CUDA 12.6 需要 NVIDIA 驱动版本 >=560.35.05 或更高。
运行 nvidia-smi 检查当前驱动版本。
应该使用哪个 Python 版本?
PyTorch 2.9.1 支持 Python 版本: 3.10, 3.11, 3.12。
推荐使用 Python 3.11 以获得最佳兼容性。
如何验证容器中的 GPU 访问?
构建镜像后运行:
docker run --gpus all your-image python -c "import torch; print(torch.cuda.is_available())"
如果 GPU 可访问,将输出 True。