From df33b6749a5f2bda9cd6408a7517f9ed376876ca Mon Sep 17 00:00:00 2001 From: Lukas Date: Wed, 27 Nov 2024 16:24:43 +0100 Subject: [PATCH 1/3] Added support for Docker. Container can easily be started with docker compose --- .dockerignore | 2 ++ Dockerfile | 19 +++++++++++++++++++ README.md | 10 ++++++++++ compose.yml | 16 ++++++++++++++++ launch.py | 6 +++++- modules/cmd_args.py | 1 + webui-user.sh | 2 +- 7 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000000..f456d7997c5 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +models +models/ \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000000..86fd6d62fc2 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,19 @@ +FROM python:3.10-bookworm + +WORKDIR /webui + +RUN apt-get update && \ + apt-get install ffmpeg libsm6 libxext6 dos2unix google-perftools -y + +COPY . . + +RUN dos2unix ./webui.sh ./webui-user.sh + +RUN groupadd --system --gid 1000 webui && \ + useradd webui --uid 1000 --gid 1000 --create-home --shell /bin/bash && \ + chown -R webui:webui . +USER 1000:1000 + +RUN ./webui.sh --prepare-environment-only --skip-torch-cuda-test + +CMD [ "./webui.sh", "--skip-prepare-environment" ] diff --git a/README.md b/README.md index bc62945c0c5..f9beae23af6 100644 --- a/README.md +++ b/README.md @@ -104,6 +104,16 @@ Alternatively, use online services (like Google Colab): - [List of Online Services](https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Online-Services) +### Running with Docker + +DISCLAIMER: This currently only works with NVIDIA GPUs + +You need to have [Docker](https://www.docker.com/) installed on your system. Then clone this repository and execute `docker compose up` in the root of the repository. The first time you execute this command will take a long time as all the dependencies are installed. Subsequent runs of the command should start up the webui pretty much instantly. To stop the webui press CTRL+C and wait a few seconds. + +Models are provided to the Docker container using a bind mount. This means that if you add a new model to the models directory it should be available in the webui after a checkpoint refresh without needing to rebuild or restart the container. + +The server will be accessible at [localhost:7860](localhost:7860) + ### Installation on Windows 10/11 with NVidia-GPUs using release package 1. Download `sd.webui.zip` from [v1.0.0-pre](https://github.com/AUTOMATIC1111/stable-diffusion-webui/releases/tag/v1.0.0-pre) and extract its contents. 2. Run `update.bat`. diff --git a/compose.yml b/compose.yml new file mode 100644 index 00000000000..2088e357cd7 --- /dev/null +++ b/compose.yml @@ -0,0 +1,16 @@ +services: + webui: + build: . + volumes: + - type: bind + source: ./models + target: /webui/models + ports: + - 7860:7860 + deploy: + resources: + reservations: + devices: + - driver: nvidia + count: all + capabilities: [gpu] \ No newline at end of file diff --git a/launch.py b/launch.py index f83820d2534..d0565cb9829 100644 --- a/launch.py +++ b/launch.py @@ -34,6 +34,9 @@ def main(): launch_utils.startup_timer.record("initial startup") + if args.prepare_environment_only: + print("Setting up requirements wihout starting server as --setup-only flag was passed") + with launch_utils.startup_timer.subcategory("prepare environment"): if not args.skip_prepare_environment: prepare_environment() @@ -41,7 +44,8 @@ def main(): if args.test_server: configure_for_tests() - start() + if not args.prepare_environment_only: + start() if __name__ == "__main__": diff --git a/modules/cmd_args.py b/modules/cmd_args.py index d71982b2c12..ad05231d4df 100644 --- a/modules/cmd_args.py +++ b/modules/cmd_args.py @@ -126,3 +126,4 @@ parser.add_argument("--unix-filenames-sanitization", action='store_true', help="allow any symbols except '/' in filenames. May conflict with your browser and file system") parser.add_argument("--filenames-max-length", type=int, default=128, help='maximal length of filenames of saved images. If you override it, it can conflict with your file system') parser.add_argument("--no-prompt-history", action='store_true', help="disable read prompt from last generation feature; settings this argument will not create '--data_path/params.txt' file") +parser.add_argument("--prepare-environment-only", action='store_true', help="launch.py argument: only prepare environment without launching webui run with --skip-torch-cuda-test") diff --git a/webui-user.sh b/webui-user.sh index 70306c60d5b..3db30fcba27 100644 --- a/webui-user.sh +++ b/webui-user.sh @@ -10,7 +10,7 @@ #clone_dir="stable-diffusion-webui" # Commandline arguments for webui.py, for example: export COMMANDLINE_ARGS="--medvram --opt-split-attention" -#export COMMANDLINE_ARGS="" +export COMMANDLINE_ARGS="--listen" # python3 executable #python_cmd="python3" From d150bd0886ccbc3066ab64d1ef274db9667a007b Mon Sep 17 00:00:00 2001 From: Lukas Date: Sun, 22 Dec 2024 12:17:57 +0100 Subject: [PATCH 2/3] Applied changes according to comments on PR --- Dockerfile | 4 ++-- launch.py | 6 +----- modules/cmd_args.py | 1 - webui-user.sh | 2 +- 4 files changed, 4 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index 86fd6d62fc2..128340873b8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,6 +14,6 @@ RUN groupadd --system --gid 1000 webui && \ chown -R webui:webui . USER 1000:1000 -RUN ./webui.sh --prepare-environment-only --skip-torch-cuda-test +RUN ./webui.sh --exit --skip-torch-cuda-test -CMD [ "./webui.sh", "--skip-prepare-environment" ] +CMD [ "./webui.sh", "--skip-prepare-environment", "--listen" ] diff --git a/launch.py b/launch.py index d0565cb9829..f83820d2534 100644 --- a/launch.py +++ b/launch.py @@ -34,9 +34,6 @@ def main(): launch_utils.startup_timer.record("initial startup") - if args.prepare_environment_only: - print("Setting up requirements wihout starting server as --setup-only flag was passed") - with launch_utils.startup_timer.subcategory("prepare environment"): if not args.skip_prepare_environment: prepare_environment() @@ -44,8 +41,7 @@ def main(): if args.test_server: configure_for_tests() - if not args.prepare_environment_only: - start() + start() if __name__ == "__main__": diff --git a/modules/cmd_args.py b/modules/cmd_args.py index ad05231d4df..d71982b2c12 100644 --- a/modules/cmd_args.py +++ b/modules/cmd_args.py @@ -126,4 +126,3 @@ parser.add_argument("--unix-filenames-sanitization", action='store_true', help="allow any symbols except '/' in filenames. May conflict with your browser and file system") parser.add_argument("--filenames-max-length", type=int, default=128, help='maximal length of filenames of saved images. If you override it, it can conflict with your file system') parser.add_argument("--no-prompt-history", action='store_true', help="disable read prompt from last generation feature; settings this argument will not create '--data_path/params.txt' file") -parser.add_argument("--prepare-environment-only", action='store_true', help="launch.py argument: only prepare environment without launching webui run with --skip-torch-cuda-test") diff --git a/webui-user.sh b/webui-user.sh index 3db30fcba27..70306c60d5b 100644 --- a/webui-user.sh +++ b/webui-user.sh @@ -10,7 +10,7 @@ #clone_dir="stable-diffusion-webui" # Commandline arguments for webui.py, for example: export COMMANDLINE_ARGS="--medvram --opt-split-attention" -export COMMANDLINE_ARGS="--listen" +#export COMMANDLINE_ARGS="" # python3 executable #python_cmd="python3" From 3335f4ad0e12e78c8d691cd5b0cac107b8ac1911 Mon Sep 17 00:00:00 2001 From: Lukas Date: Sun, 22 Dec 2024 12:18:22 +0100 Subject: [PATCH 3/3] Added volumes for outputs, extensions, embeddings and configs so that they are persisted across restarts --- compose.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/compose.yml b/compose.yml index 2088e357cd7..0d713f4bfd4 100644 --- a/compose.yml +++ b/compose.yml @@ -5,6 +5,18 @@ services: - type: bind source: ./models target: /webui/models + - type: bind + source: ./outputs + target: /webui/outputs + - type: bind + source: ./extensions + target: /webui/extensions + - type: bind + source: ./embeddings + target: /webui/embeddings + - type: bind + source: ./configs + target: /webui/configs ports: - 7860:7860 deploy: