From 065851342cbfb61862dfea342c5968d98abbd3a5 Mon Sep 17 00:00:00 2001
From: Jan Grewe <jan@faked.org>
Date: Fri, 19 May 2023 23:02:50 +0200
Subject: [PATCH] use data-dir

---
 Dockerfile.a1111 => Dockerfile.automatic1111 | 12 ++---
 Dockerfile.vlad                              | 24 +++++++++
 README.md                                    | 52 +++++++++++++++-----
 3 files changed, 69 insertions(+), 19 deletions(-)
 rename Dockerfile.a1111 => Dockerfile.automatic1111 (62%)
 create mode 100644 Dockerfile.vlad

diff --git a/Dockerfile.a1111 b/Dockerfile.automatic1111
similarity index 62%
rename from Dockerfile.a1111
rename to Dockerfile.automatic1111
index cc30b0c..cdc08d1 100644
--- a/Dockerfile.a1111
+++ b/Dockerfile.automatic1111
@@ -10,19 +10,17 @@ RUN apt-get -qq update -y \
  && rm -rf /var/lib/apt/lists/*
 
 RUN git clone --depth 1 --branch v${VERSION} -c advice.detachedHead=false \
-    https://github.com/AUTOMATIC1111/stable-diffusion-webui.git /stable-diffusion-webui
+    https://github.com/AUTOMATIC1111/stable-diffusion-webui.git /app
 
-WORKDIR /stable-diffusion-webui
-VOLUME /stable-diffusion-webui/models/VAE-approx
+WORKDIR /app
 
 ENV PIP_ROOT_USER_ACTION=ignore
-RUN sed -i -e 's/    start()/    #start()/g' /stable-diffusion-webui/launch.py \
+RUN sed -i -e 's/    start()/    #start()/g' /app/launch.py \
  && python launch.py --skip-torch-cuda-test \
- && sed -i -e 's/    #start()/    start()/g' /stable-diffusion-webui/launch.py
-
+ && sed -i -e 's/    #start()/    start()/g' /app/launch.py
 RUN rm -r /root/.cache/pip
 
 EXPOSE 7860
 
-ENTRYPOINT ["python", "webui.py", "--listen", "--disable-console-progressbars", "--enable-insecure-extension-access"]
+ENTRYPOINT ["python", "launch.py", "--listen", "--data-dir", "/app/data", "--disable-console-progressbars", "--enable-insecure-extension-access"]
 CMD ["--api", "--opt-sdp-no-mem-attention", "--opt-channelslast"]
diff --git a/Dockerfile.vlad b/Dockerfile.vlad
new file mode 100644
index 0000000..6d364e3
--- /dev/null
+++ b/Dockerfile.vlad
@@ -0,0 +1,24 @@
+FROM nvidia/cuda:11.8.0-base-ubuntu22.04
+
+ARG VERSION
+ENV VERSION=master
+
+ENV DEBIAN_FRONTEND=noninteractive
+RUN apt-get -qq update -y \
+ && apt-get -qq install -y --no-install-recommends \
+    git git-lfs libgl1 pkg-config python-is-python3 python3-dev python3-pip \
+ && rm -rf /var/lib/apt/lists/*
+
+RUN git clone --depth 1 --branch ${VERSION} -c advice.detachedHead=false \
+    https://github.com/vladmandic/automatic.git /app
+
+WORKDIR /app
+
+ENV TORCH_COMMAND="torch torchaudio torchvision --index-url https://download.pytorch.org/whl/cu118"
+ENV PIP_ROOT_USER_ACTION=ignore
+RUN python installer.py
+RUN rm -r /root/.cache/pip
+
+EXPOSE 7860
+
+ENTRYPOINT ["python", "launch.py", "--listen", "--data-dir", "/app/data"]
diff --git a/README.md b/README.md
index 65f98cd..1ce3b94 100644
--- a/README.md
+++ b/README.md
@@ -1,19 +1,47 @@
-# AUTOMATIC1111
-Set the name of the Docker image:
+# Stable Diffusion WebUI in Docker
+
+## Available Versions
+Set the version of the Docker image you want to build:
+
+#### AUTOMATIC1111:
+To build the Stable Diffusion WebUI by AUTOMATIC111 from https://github.com/AUTOMATIC1111/stable-diffusion-webui
 ```
-export DOCKER_IMAGE=dcr.faked.org/stable-diffusion-webui:latest
+export IMAGE_VERSION="automatic1111"
 ```
-Build the Docker image:
+#### Vlad
+To build the Stable Diffusion WebUI by Vlad Mandic from https://github.com/vladmandic/automatic/
 ```
-docker build -f Dockerfile.a1111 -t ${DOCKER_IMAGE} .
+export IMAGE_VERSION="vlad"
 ```
-Run the Docker image:
+
+## Build the image (and optionally push it to your registry)
 ```
-docker run --gpus all --rm --name stable-diffusion -p 7860:7860 \
-  -v /storage/stable-diffusion/extensions:/stable-diffusion-webui/extensions \
-  -v /storage/stable-diffusion/embeddings:/stable-diffusion-webui/embeddings \
-  -v /storage/stable-diffusion/models:/stable-diffusion-webui/models \
-  -v /storage/stable-diffusion/outputs:/stable-diffusion-webui/outputs \
+export IMAGE_NAME=registry.example.com/stable-diffusion-webui:${IMAGE_VERSION}
+docker build -f Dockerfile.${IMAGE_VERSION} -t ${IMAGE_NAME} .
+docker push ${IMAGE_NAME}
+```
+
+## Run the container
+Run the image without retaining any data or outputs on exit:
+
+```
+docker run --gpus all --rm --name stable-diffusion -p 7860:7860 ${IMAGE_NAME}
+```
+
+Run the image with persisted models, downloaded data and outputs:
+```
+docker run --tty --gpus all --rm --name stable-diffusion -p 7860:7860 \
+  -v /storage/stable-diffusion/data/${IMAGE_VERSION}:/app/data \
+  -v /storage/stable-diffusion/repositories:/app/repositories \
   -v /storage/stable-diffusion/cache:/root/.cache \
-  ${DOCKER_IMAGE}
+  -v /storage/stable-diffusion/outputs:/app/outputs \
+  ${IMAGE_NAME}
 ```
+
+# Troubleshooting
+* There is no output to the console when starting the AUTOMATIC1111 image until you generate an image.
+  This can be fixed by adding the `--tty` argument after `docker run`
+* The Vlad image asks you to confirm the download of the default model if it doesn't find one (e.g. because you mounted an empty data directory, or ran the image without a mounted data directory).
+  If that happens, the container will exit with an error, as you can't confirm the download.
+  To fix this, run the container with the `--interactive` argument after `docker run`, then you can confirm the download.
+  If you are using a moounted data directory, this should only be necessary for the first run, as it will find the downloaded model the next time you start the image.
-- 
GitLab