Skip to content

🐳 Dockerfile for 🖼️ Stable Diffusion WebUI, only runtime environment & bootstrapping scripts. | SD-WebUI 的容器镜像,但仅含运行环境与安装启动脚本。

License

Notifications You must be signed in to change notification settings

YanWenKun/sd-webui-docker-base

Repository files navigation

Yet another Docker image for Stable Diffusion WebUI

GitHub Workflow Status
Concept Design

This repo is inspired by AbdBarho, with a different approach, and only supports AUTOMATIC1111.

Idea

A heavy user of SD-WebUI would probably have a lot of models, extensions, and want everything up-to-date. This Docker image is how I figured out to manage them:

Keeping the app & data in one place, and leaving the dependency in Docker.

How it works

  1. At first start, a script will download latest SD-WebUI, some extensions and essential models.

  2. The whole SD-WebUI will be stored in a local folder (./storage/stable-diffusion-webui).

  3. If you already have a SD-WebUI bundle, put it there and make an empty file (./storage/.sdw-download-complete) so the start script will skip downloading.

  4. At every restart of the container, a script will update SD-WebUI & its extensions.

Prerequisites

  • NVIDIA GPU with ≥6GB VRAM (for 4GB see Q & A).

  • Latest NVIDIA GPU Drivers, Both Game and Studio version will work.

  • Docker Installed

Usage

A. Using docker compose
git clone https://github.com/YanWenKun/sd-webui-docker-base.git

cd sd-webui-docker-base

docker compose up --detach

# Update image (only when Python components is outdated)
git pull
docker compose pull
docker compose up --detach --remove-orphans
docker image prune
B. Using docker run
mkdir -p storage

docker run -it \
  --name sd-webui \
  --gpus all \
  -p 7860:7860 \
  -v "$(pwd)"/storage:/home/runner \
  --env CLI_ARGS="--xformers --medvram --allow-code --api --enable-insecure-extension-access" \
  yanwk/sd-webui-base

# Update image (only when Python components is outdated)
docker rm sd-webui
docker pull yanwk/sd-webui-base
# Then re-run 'docker run' above again

Once the app is loaded, visit http://localhost:7860/

Q & A

Q: My GPU only has 4GB VRAM
A: Modify args in CLI_ARGS, change --medvram to --lowvram.

Q: Can I run it without a NVIDIA GPU?
A: Use CPU!

  1. In docker-compose.yml, delete deploy: section.

    • Or in docker run, delete --gpus all.

  2. In CLI_ARGS, change --xformers --medvram to --use-cpu all --no-half --precision full.

More CLI_ARGS available at SD-WebUI Wiki.

Q: Why are you using latest version of dependencies?
A: Try to squeeze more performance out of GPUs (using latest stable version of PyTorch & xFormers).

Q: Will upstream changes break this image?
A: Probably will with major changes in launch.py & requirements_versions.txt, otherwise unlikely. User’s data will always stay safe. User just need to update Docker image after I update this repo.

Some commands for debugging

Build the image, print all logs to STDOUT.
docker build . -f Dockerfile -t yanwk/sd-webui-base --progress=plain
Run a one-time container
docker run -it --rm --gpus all -p 7860:7860 \
  -v "$(pwd)"/storage:/home/runner \
  --env CLI_ARGS="--xformers --medvram" \
  yanwk/sd-webui-base
Run into a root bash
docker run -it --rm --gpus all \
  -v "$(pwd)"/storage:/home/runner \
  -p 7860:7860 \
  --user root \
  -e CLI_ARGS="--xformers --medvram --allow-code --api --enable-insecure-extension-access --ckpt ./test/test_files/empty.pt" \
  yanwk/sd-webui-base:latest /bin/bash
Run a rootless container (Podman)

Inside the pod, Podman will mount volume as root, scripts will run as root. And from the host side, we see files keep their original ownership.

mkdir -p storage

podman pull docker.io/yanwk/sd-webui-base:latest

podman run -it --rm \
  --name sd-webui-rootless \
  --device nvidia.com/gpu=all \
  --security-opt label=disable \
  -p 7860:7860 \
  -v "$(pwd)"/storage:/root \
  --user root \
  --workdir /root \
  -e CLI_ARGS="--xformers --medvram --allow-code --api --enable-insecure-extension-access" \
  yanwk/sd-webui-base:latest \
  /bin/bash /home/scripts/root-wrapper.sh

Special Thanks

Thank again for AbdBarho's devotion and brilliant works, which my inspiration emerged from. I would definitely consider webui-docker if I want to deploy multiple WebUIs and only one set of models.

License

This open source license is written and valid both in Chinese and English, how good is that!

About

🐳 Dockerfile for 🖼️ Stable Diffusion WebUI, only runtime environment & bootstrapping scripts. | SD-WebUI 的容器镜像,但仅含运行环境与安装启动脚本。

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published