From 6b3673affe783ef2e178c0fd1d0ece04f92f65f9 Mon Sep 17 00:00:00 2001 From: oromis995 <54419741+oromis995@users.noreply.github.com> Date: Thu, 14 May 2026 22:11:15 -0500 Subject: [PATCH] Docker --- README.md | 3 ++ docker/.dockerignore | 6 +++ docker/Dockerfile | 77 ++++++++++++++++++++++++++++++++++++ docker/README.md | 92 ++++++++++++++++++++++++++++++++++++++++++++ docker/entrypoint.sh | 24 ++++++++++++ 5 files changed, 202 insertions(+) create mode 100644 docker/.dockerignore create mode 100644 docker/Dockerfile create mode 100644 docker/README.md create mode 100644 docker/entrypoint.sh diff --git a/README.md b/README.md index 7f7c11b6..045bfce5 100644 --- a/README.md +++ b/README.md @@ -339,6 +339,9 @@ The name "Forge" is inspired by "Minecraft Forge". This project aims to become t > [!Tip] > For **Linux** and **macOS**, refer to [Wiki](https://github.com/Haoming02/sd-webui-forge-classic/wiki/Unix) +> [!Tip] +> For **Docker** (`Nvidia`), refer to [Docker](docker/) +
> [!Tip] diff --git a/docker/.dockerignore b/docker/.dockerignore new file mode 100644 index 00000000..c0014c07 --- /dev/null +++ b/docker/.dockerignore @@ -0,0 +1,6 @@ +__pycache__ +.DS_Store +data +*.log +*.pyc +*.pyo diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 00000000..c7a47d40 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,77 @@ +# syntax=docker/dockerfile:1 +# Forge Neo | NVIDIA GPU + +ARG CUDA_VERSION=12.6.3 + +FROM nvidia/cuda:${CUDA_VERSION}-runtime-ubuntu22.04 + +# See: https://download.pytorch.org/whl/ +ARG TORCH_INDEX=cu126 + +ENV DEBIAN_FRONTEND=noninteractive \ + PYTHONUNBUFFERED=1 \ + PYTHONDONTWRITEBYTECODE=1 \ + UV_PYTHON_DOWNLOADS=automatic \ + UV_NO_CACHE=1 \ + TORCH_INDEX_URL=https://download.pytorch.org/whl/${TORCH_INDEX} + +# uv binary +COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv + +# Dependencies +RUN apt-get update && apt-get install -y --no-install-recommends \ + build-essential \ + curl \ + ffmpeg \ + git \ + libgl1 \ + libglib2.0-0 \ + libgomp1 \ + libtcmalloc-minimal4 \ + && rm -rf /var/lib/apt/lists/* + +# Non-Root User (UID 99 / GID 100 = nobody:users) +RUN groupadd -g 100 users 2>/dev/null || true \ + && useradd -u 99 -g 100 -d /home/forge -m -s /bin/bash forge + +WORKDIR /home/forge/sd-webui + +# Clone at build time +RUN git clone --branch neo --depth 1 --filter blob:none \ + https://github.com/Haoming02/sd-webui-forge-classic.git . \ + && chown -R 99:100 /home/forge + +USER forge + +# Python 3.13 Virtual ENVironment +RUN uv venv venv --python 3.13 --seed + +ENV VIRTUAL_ENV="/home/forge/sd-webui/venv" \ + PATH="/home/forge/sd-webui/venv/bin:$PATH" \ + PYTHON="/home/forge/sd-webui/venv/bin/python3.13" + +# PyTorch Pre-Install +RUN uv pip install torch torchvision \ + --index-url "https://download.pytorch.org/whl/${TORCH_INDEX}" + +# Persistent Data Directories +RUN mkdir -p \ + models/Stable-diffusion \ + models/VAE \ + models/Lora \ + models/ControlNet \ + extensions \ + config \ + output + +# Runtime +COPY --chown=99:100 entrypoint.sh /home/forge/sd-webui/entrypoint.sh +RUN chmod +x /home/forge/sd-webui/entrypoint.sh + +EXPOSE 7860 + +# extra time for prepare_environment() to run on first start +HEALTHCHECK --interval=30s --timeout=10s --start-period=300s --retries=15 \ + CMD curl -f http://localhost:7860/ || exit 1 + +ENTRYPOINT ["/home/forge/sd-webui/entrypoint.sh"] diff --git a/docker/README.md b/docker/README.md new file mode 100644 index 00000000..c27d85b3 --- /dev/null +++ b/docker/README.md @@ -0,0 +1,92 @@ +

Stable Diffusion WebUI Forge - Neo (Docker)

+ +> [!Warning] +> Requires an **NVIDIA** GPU
+> Ensure driver is up to date (`560+` required) + +
+ +## Unraid Deployment + + + + + + + + + + + + + + + + + + + + + + +
Container PathPurpose
+ /home/forge/sd-webui/models + Checkpoint, Text Encoder, VAE, LoRA, ControlNet
+ /home/forge/sd-webui/output + Generated Images
+ /home/forge/sd-webui/extensions + User-Installed Extensions
+ /home/forge/sd-webui/config + User Settings
+ +- The container runs as **UID 99** / **GID 100** (`nobody:users`) to match Unraid's default share permissions + +
+ +## Building Locally + +```bash +git clone https://github.com/Haoming02/sd-webui-forge-classic sd-webui-forge-neo --branch neo +cd sd-webui-forge-neo/docker +docker build -t forge-neo-local . +``` + +
+ +## Pre-Built Image + +> a non-official pre-built image is maintained on Docker Hub by [@oromis995](https://github.com/oromis995): + +```bash +docker pull oromis995/sd-forge-neo:latest +``` + +
+ +## Image Details + + + + + + + + + + + + + + + + + + + + + + +
Basenvidia/cuda:12.6.3-runtime-ubuntu22.04
Python3.13 via uv
PyTorchLatest (cu126)
Userforge (UID 99 / GID 100)
Port7860
+ +> [!Note] +> On the first run, `prepare_environment()` will install requirements and dependencies. This may take a few minutes diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh new file mode 100644 index 00000000..f4f6e512 --- /dev/null +++ b/docker/entrypoint.sh @@ -0,0 +1,24 @@ +#!/bin/bash +set -euo pipefail + +# TCMalloc reduces memory fragmentation under large model workloads +export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libtcmalloc_minimal.so.4 + +# Read COMMANDLINE_ARGS then unset it +RAW_ARGS="${COMMANDLINE_ARGS:-}" +unset COMMANDLINE_ARGS + +EXTRA_ARGS=() +if [[ -n "$RAW_ARGS" ]]; then + read -ra EXTRA_ARGS <<< "$RAW_ARGS" +fi + +# Symlink settings files into the config bind-mount so they persist across container recreations +for f in config.json ui-config.json styles.csv user.css; do + ln -sf /home/forge/sd-webui/config/$f /home/forge/sd-webui/$f +done + +exec python /home/forge/sd-webui/launch.py \ + --listen \ + "${EXTRA_ARGS[@]}" \ + "$@"