推荐配置 驱动 >=520.61.05

TensorFlow 2.14.0 + CUDA 11.8

生成经过验证的生产级 Dockerfile 配置

配置摘要

框架
TensorFlow 2.14.0
CUDA 版本
11.8
Python 支持
3.9, 3.10, 3.11
最低驱动
>=520.61.05
安装命令
pip install tensorflow==2.14.0

TensorFlow 2.14.0 新特性

  • 经典 tf.keras API
  • 广泛的库生态支持
  • 经过验证的生产稳定性

最佳用途

适用场景

  • 遗留系统维护
  • 最大程度的第三方兼容性
  • 版本锁定的企业系统

CUDA 11.8 优势

  • T4, V100 等旧 GPU
  • 最大兼容性
  • 经济高效的推理

限制: 缺少新版 CUDA 优化

生成 Dockerfile

配置选项

本地 GPU 或 CPU 环境

需要 NVIDIA 驱动版本 >=520.61.05
Dockerfile
1# syntax=docker/dockerfile:1
2# ^ Required for BuildKit cache mounts and advanced features
3
4# Generated by DockerFit (https://tools.eastondev.com/docker)
5# TENSORFLOW 2.14.0 + CUDA 11.8 | Python 3.11
6# Multi-stage build for optimized image size
7
8# ==============================================================================
9# Stage 1: Builder - Install dependencies and compile
10# ==============================================================================
11FROM nvidia/cuda:11.8.0-cudnn8-devel-ubuntu22.04 AS builder
12
13# Build arguments
14ARG DEBIAN_FRONTEND=noninteractive
15
16# Environment variables
17ENV PYTHONUNBUFFERED=1
18ENV PYTHONDONTWRITEBYTECODE=1
19ENV TORCH_CUDA_ARCH_LIST="7.5;8.0;8.6"
20
21# 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 git
31 && rm -rf /var/lib/apt/lists/*
32
33# Create virtual environment
34ENV VIRTUAL_ENV=/opt/venv
35RUN python3.11 -m venv $VIRTUAL_ENV
36ENV PATH="$VIRTUAL_ENV/bin:$PATH"
37
38# Upgrade pip
39RUN pip install --no-cache-dir --upgrade pip setuptools wheel
40
41# Install TensorFlow with BuildKit cache
42RUN --mount=type=cache,target=/root/.cache/pip \
43 pip install tensorflow==2.14.0
44
45# Install project dependencies
46COPY requirements.txt .
47RUN --mount=type=cache,target=/root/.cache/pip \
48 pip install -r requirements.txt
49
50# ==============================================================================
51# Stage 2: Runtime - Minimal production image
52# ==============================================================================
53FROM nvidia/cuda:11.8.0-cudnn8-runtime-ubuntu22.04 AS runtime
54
55# Labels
56LABEL maintainer="Generated by DockerFit"
57LABEL version="2.14.0"
58LABEL description="TENSORFLOW 2.14.0 + CUDA 11.8"
59
60# Environment variables
61ENV PYTHONUNBUFFERED=1
62ENV PYTHONDONTWRITEBYTECODE=1
63ENV NVIDIA_VISIBLE_DEVICES=all
64ENV NVIDIA_DRIVER_CAPABILITIES=compute,utility
65
66# Install Python 3.11 runtime from deadsnakes PPA (Ubuntu 22.04)
67RUN apt-get update && apt-get install -y --no-install-recommends \
68 software-properties-common \
69 && add-apt-repository -y ppa:deadsnakes/ppa \
70 && apt-get update && apt-get install -y --no-install-recommends \
71 python3.11 \
72 libgomp1
73 && apt-get remove -y software-properties-common \
74 && apt-get autoremove -y \
75 && rm -rf /var/lib/apt/lists/*
76
77# Create non-root user for security
78ARG USERNAME=appuser
79ARG USER_UID=1000
80ARG USER_GID=$USER_UID
81RUN groupadd --gid $USER_GID $USERNAME \
82 && useradd --uid $USER_UID --gid $USER_GID -m $USERNAME
83
84# Copy virtual environment from builder
85COPY --from=builder --chown=$USERNAME:$USERNAME /opt/venv /opt/venv
86ENV VIRTUAL_ENV=/opt/venv
87ENV PATH="$VIRTUAL_ENV/bin:$PATH"
88
89# Set working directory
90WORKDIR /app
91
92# Copy application code
93COPY --chown=$USERNAME:$USERNAME . .
94
95# Switch to non-root user
96USER $USERNAME
97
98# Expose port
99EXPOSE 8000
100
101# Default command
102CMD ["python", "main.py"]
🚀 推荐部署

高性能 GPU 与 AI 云服务器

为您的 Docker 容器提供强大的 NVIDIA 算力支持,支持 A100/H100,全球 32 个机房可选。

  • 支持 NVIDIA A100/H100 GPU 实例
  • 按小时计费,测试成本低至 $0.004/h
  • 全球 32+ 数据中心,极低访问延迟
  • 一键运行容器化应用与裸金属服务器
🎁 立即部署

常见问题

需要什么版本的 NVIDIA 驱动?

TensorFlow 2.14.0 + CUDA 11.8 需要 NVIDIA 驱动版本 >=520.61.05 或更高。

运行 nvidia-smi 检查当前驱动版本。

如何安装支持 CUDA 的 TensorFlow?

TensorFlow 2.14.0 使用以下安装命令:

pip install tensorflow==2.14.0

从 TensorFlow 2.15+ 开始,CUDA 库通过 tensorflow[and-cuda] 打包。

如何验证容器中的 GPU 访问?

构建镜像后运行:

docker run --gpus all your-image python -c "import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))"

将显示可用的 GPU 设备列表。