驱动 >=510.47.03
PyTorch 1.13.1 + CUDA 11.6
生成经过验证的生产级 Dockerfile 配置
配置摘要
框架
PyTorch 1.13.1
CUDA 版本
11.6
Python 支持
3.7, 3.8, 3.9, 3.10
最低驱动
>=510.47.03
PyTorch 1.13.1 新特性
- 最后一个主要的 PyTorch 1.x 版本
- 完整的 CUDA 11.x 支持
- 成熟的生产环境验证
最佳用途
适用场景
- 维护 1.x 版本的系统
- 最大程度兼容旧代码
- 无法升级到 2.x 的项目
CUDA 11.6 优势
- PyTorch 1.13.x 部署
- 最大向后兼容性
- 较旧的 Ubuntu 20.04 系统
限制: 已弃用的 CUDA 版本,建议使用 11.7+
生成 Dockerfile
配置选项
本地 GPU 或 CPU 环境
需要 NVIDIA 驱动版本 >=510.47.03
Dockerfile
1# syntax=docker/dockerfile:12# ^ Required for BuildKit cache mounts and advanced features34# Generated by DockerFit (https://tools.eastondev.com/docker)5# PYTORCH 1.13.1 + CUDA 11.6 | Python 3.116# Multi-stage build for optimized image size78# ==============================================================================9# Stage 1: Builder - Install dependencies and compile10# ==============================================================================11FROM nvidia/cuda:11.6.2-cudnn8-devel-ubuntu20.04 AS builder1213# Build arguments14ARG DEBIAN_FRONTEND=noninteractive1516# Environment variables17ENV PYTHONUNBUFFERED=118ENV PYTHONDONTWRITEBYTECODE=119ENV TORCH_CUDA_ARCH_LIST="7.5;8.0;8.6"2021# Install Python 3.11 and build tools (native)22RUN apt-get update && apt-get install -y --no-install-recommends \23 python3.11 \24 python3.11-venv \25 python3.11-dev \26 build-essential \27 git28 && rm -rf /var/lib/apt/lists/*2930# Create virtual environment31ENV VIRTUAL_ENV=/opt/venv32RUN python3.11 -m venv $VIRTUAL_ENV33ENV PATH="$VIRTUAL_ENV/bin:$PATH"3435# Upgrade pip36RUN pip install --no-cache-dir --upgrade pip setuptools wheel3738# Install PyTorch with BuildKit cache39RUN --mount=type=cache,target=/root/.cache/pip \40 pip install torch torchvision torchaudio \41 --index-url https://download.pytorch.org/whl/cu1164243# Install project dependencies44COPY requirements.txt .45RUN --mount=type=cache,target=/root/.cache/pip \46 pip install -r requirements.txt4748# ==============================================================================49# Stage 2: Runtime - Minimal production image50# ==============================================================================51FROM nvidia/cuda:11.6.2-cudnn8-runtime-ubuntu20.04 AS runtime5253# Labels54LABEL maintainer="Generated by DockerFit"55LABEL version="1.13.1"56LABEL description="PYTORCH 1.13.1 + CUDA 11.6"5758# Environment variables59ENV PYTHONUNBUFFERED=160ENV PYTHONDONTWRITEBYTECODE=161ENV NVIDIA_VISIBLE_DEVICES=all62ENV NVIDIA_DRIVER_CAPABILITIES=compute,utility6364# Install runtime dependencies (native Python 3.11)65RUN apt-get update && apt-get install -y --no-install-recommends \66 python3.11 \67 libgomp168 && rm -rf /var/lib/apt/lists/*6970# Create non-root user for security71ARG USERNAME=appuser72ARG USER_UID=100073ARG USER_GID=$USER_UID74RUN groupadd --gid $USER_GID $USERNAME \75 && useradd --uid $USER_UID --gid $USER_GID -m $USERNAME7677# Copy virtual environment from builder78COPY --from=builder --chown=$USERNAME:$USERNAME /opt/venv /opt/venv79ENV VIRTUAL_ENV=/opt/venv80ENV PATH="$VIRTUAL_ENV/bin:$PATH"8182# Set working directory83WORKDIR /app8485# Copy application code86COPY --chown=$USERNAME:$USERNAME . .8788# Switch to non-root user89USER $USERNAME9091# Expose port92EXPOSE 80009394# Default command95CMD ["python", "main.py"]
🚀 推荐部署
高性能 GPU 与 AI 云服务器
为您的 Docker 容器提供强大的 NVIDIA 算力支持,支持 A100/H100,全球 32 个机房可选。
- 支持 NVIDIA A100/H100 GPU 实例
- 按小时计费,测试成本低至 $0.004/h
- 全球 32+ 数据中心,极低访问延迟
- 一键运行容器化应用与裸金属服务器
常见问题
需要什么版本的 NVIDIA 驱动?
PyTorch 1.13.1 + CUDA 11.6 需要 NVIDIA 驱动版本 >=510.47.03 或更高。
运行 nvidia-smi 检查当前驱动版本。
应该使用哪个 Python 版本?
PyTorch 1.13.1 支持 Python 版本: 3.7, 3.8, 3.9, 3.10。
推荐使用 Python 3.9 以获得最佳兼容性。
如何验证容器中的 GPU 访问?
构建镜像后运行:
docker run --gpus all your-image python -c "import torch; print(torch.cuda.is_available())"
如果 GPU 可访问,将输出 True。