sudo docker run --rm --gpus all nvidia/cuda:12.4.0-base-ubuntu22.04 nvidia-smi
如果您能在此容器的输出中看到您的 NVIDIA 5090 显卡信息,那么恭喜您,环境已准备就绪!
解决 RTX 5090 (Blackwell) 兼容性问题
解决在 NVIDIA GeForce RTX 5090 (Blackwell 架构) 上遇到的 sm_120 不兼容和 no kernel image is available 错误。
NVIDIA GeForce RTX 5090with CUDA capability sm_120 isnot compatible with the current PyTorch installation. The current PyTorch install supports CUDA capabilities sm_50 sm_60 sm_61 sm_70 sm_75 sm_80 sm_86 sm_90. ... RuntimeError: CUDA error: no kernel image is available for execution on the device
# --- Base Image ---
# Start from the official NVIDIA CUDA development image for Ubuntu 20.04
FROM nvidia/cuda:12.8.0-devel-ubuntu20.04
# --- Environment Variables ---
# Set all ENV vars at the top for clarity and configuration management.
ENV DEBIAN_FRONTEND=noninteractive
ENV TZ=Asia/Shanghai
ENV HF_ENDPOINT=https://hf-mirror.com
# ENV HF_ENDPOINT=https://huggingface.co
# Add the virtual environment's bin directory to the PATH.
# This allows you to run `python` and `pip` directly without the full path.
ENV PATH="/app/venv/bin:$PATH"
# --- System-Level Dependencies ---
# Combine all apt commands into a single RUN layer to reduce image size.
RUN apt-get update && \
apt-get install -y --no-install-recommends software-properties-common && \
# Add the PPA for Python 3.10
add-apt-repository ppa:deadsnakes/ppa && \
add-apt-repository ppa:git-core/ppa && \
apt-get update && \
# Install all required system packages from all stages at once.
apt-get install -y --no-install-recommends \
git \
wget \
python3.10 \
python3.10-dev \
python3.10-venv \
python3-pip \
build-essential \
libgl1-mesa-glx \
libglib2.0-0 \
nscd \
vim \
# Add the dependencies for pycairo (needed by svglib)
libcairo2-dev \
pkg-config \
# Clean up the apt cache to keep the final image lean.
&& rm -rf /var/lib/apt/lists/*
# 配置 Git 信任所有挂载的目录。* 是一个通配符,可以让这个设置对您将来添加的任何插件都生效。
RUN git config --global --add safe.directory '*'
# --- Python Environment & Dependencies ---
# Set the working directory for the application.
WORKDIR /app
# Create the virtual environment and install all Python packages in one layer.
# This optimizes Docker's caching, as this layer only rebuilds if dependencies change.
RUN python3.10 -m venv venv && \
# Configure pip to use mirror URLs for faster downloads.
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple && \
pip config set global.extra-index-url https://download.pytorch.org/whl/nightly/cu128 && \
# Upgrade pip and install all packages using --no-cache-dir to reduce image size.
pip install --no-cache-dir --upgrade pip && \
# Install PyTorch
pip install --no-cache-dir --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/cu128 && \
# Install transformers, diffusers, and other packages
pip install --no-cache-dir \
transformers==4.30.2 \
diffusers==0.30.0 \
accelerate \
xformers \
open-clip-torch \
chardet \
fastapi \
PyExecJS \
lxml \
tqdm \
pathos \
cryptography \
openai \
boto3 \
aliyun-python-sdk-core \
aliyun-python-sdk-alimt \
svglib \
insightface
# --- Application Code & Data ---
# Copy the application source code. Changes to these files will invalidate the cache from this point onward.
# 【最终优化】使用 git clone 代替 ADD,确保 .git 目录存在
# RUN git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git /app
ADD stable-diffusion-webui/ .
# WORKDIR /app
# You can uncomment the line below if you consolidate your pip packages into a requirements file.
RUN pip install --no-cache-dir -r requirements_versions.txt
# --- Runtime Configuration ---
# Expose the port the application will listen on.
EXPOSE 7860
# Define the default command to execute when the container starts.
CMD [
"python", "launch.py",
"--listen",
"--port", "7860",
"--xformers",
"--enable-insecure-extension-access",
"--api",
"--skip-version-check"
]
# --- Base Image ---
# Start from the official NVIDIA CUDA development image for Ubuntu 20.04
FROM nvidia/cuda:12.8.0-devel-ubuntu20.04
# --- Environment Variables ---
# Set all ENV vars at the top for clarity and configuration management.
ENV DEBIAN_FRONTEND=noninteractive
ENV TZ=Asia/Shanghai
ENV HF_ENDPOINT=https://hf-mirror.com
# ENV HF_ENDPOINT=https://huggingface.co
# Add the virtual environment's bin directory to the PATH.
# This allows you to run `python` and `pip` directly without the full path.
ENV PATH="/app/venv/bin:$PATH"
# --- System-Level Dependencies ---
# Combine all apt commands into a single RUN layer to reduce image size.
RUN apt-get update && \
apt-get install -y --no-install-recommends software-properties-common && \
# Add the PPA for Python 3.10
add-apt-repository ppa:deadsnakes/ppa && \
add-apt-repository ppa:git-core/ppa && \
apt-get update && \
# Install all required system packages from all stages at once.
apt-get install -y --no-install-recommends \
git \
wget \
python3.10 \
python3.10-dev \
python3.10-venv \
python3-pip \
build-essential \
libgl1-mesa-glx \
libglib2.0-0 \
nscd \
vim \
# Add the dependencies for pycairo (needed by svglib)
libcairo2-dev \
pkg-config \
# Clean up the apt cache to keep the final image lean.
&& rm -rf /var/lib/apt/lists/*
# 配置 Git 信任所有挂载的目录。* 是一个通配符,可以让这个设置对您将来添加的任何插件都生效。
RUN git config --global --add safe.directory '*'
# --- Python Environment & Dependencies ---
# Set the working directory for the application.
WORKDIR /app
# Create the virtual environment and install all Python packages in one layer.
# This optimizes Docker's caching, as this layer only rebuilds if dependencies change.
RUN python3.10 -m venv venv && \
. /app/venv/bin/activate && \
# Configure pip to use mirror URLs for faster downloads.
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple && \
pip config set global.extra-index-url https://download.pytorch.org/whl/nightly/cu128 && \
# Upgrade pip and install all packages using --no-cache-dir to reduce image size.
pip install --no-cache-dir --upgrade pip && \
# Install PyTorch
pip install --no-cache-dir --pre torch torchvision torchaudio xformers --index-url https://download.pytorch.org/whl/nightly/cu128 && \
# Install transformers, diffusers, and other packages
pip install --no-cache-dir \
transformers==4.30.2 \
diffusers==0.30.0 \
accelerate \
open-clip-torch \
chardet \
fastapi \
PyExecJS \
lxml \
tqdm \
pathos \
cryptography \
openai \
boto3 \
aliyun-python-sdk-core \
aliyun-python-sdk-alimt \
svglib \
insightface
# --- Application Code & Data ---
# Copy the application source code. Changes to these files will invalidate the cache from this point onward.
# 【最终优化】使用 git clone 代替 ADD,确保 .git 目录存在
# RUN git clone https://github.com/comfyanonymous/ComfyUI.git /app
ADD ComfyUI/ .
# Install any local packages that depend on the source code being present.
# RUN pip install --no-cache-dir -e ./repositories/k-diffusion
# You can uncomment the line below if you consolidate your pip packages into a requirements file.
RUN pip install --no-cache-dir -r requirements.txt
RUN which python && python --version
# --- Runtime Configuration ---
# Expose the port the application will listen on.
EXPOSE 8188
# Define the default command to execute when the container starts.
CMD [
"python", "main.py",
"--listen", "0.0.0.0",
"--port", "8188",
"--user-directory", "/app/userdata"
]