Skip to content

Commit 50a6693

Browse files
update Dockerfile according to comments and move to separated folder
Co-authored-by: Lukas <[email protected]> Signed-off-by: Peter Pan <[email protected]>
1 parent 5070021 commit 50a6693

File tree

9 files changed

+136
-29
lines changed

9 files changed

+136
-29
lines changed

.dockerignore

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
1-
models
2-
models/
1+
.venv
2+
.che__/
3+
*.log
4+
*.git
5+
*.gitignore
6+
docker
7+
models/*
8+
embeddings/*
9+
extensions/*

README.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,43 @@ Alternatively, use online services (like Google Colab):
106106

107107
### Running with Docker
108108

109+
#### a) Run with Docker Compose
109110
DISCLAIMER: This currently only works with NVIDIA GPUs
110111

111-
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.
112+
You need to have [Docker](https://www.docker.com/) installed on your system. Then clone this repository and execute `docker compose -f docker/compose.yml up` in the root path 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.
112113

113114
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.
114115

115116
The server will be accessible at [localhost:7860](localhost:7860)
116117

118+
#### b) Run with docker CLI
119+
```
120+
git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui
121+
cd stable-diffusion-webui
122+
export TAG=$(git describe --abbrev=0) # the image tag, here example uses the latest git tag
123+
export IMG=AUTOMATIC1111/stable-diffusion-webui:${TAG}
124+
docker build -t ${IMG} -f docker/Dockerfile .
125+
docker run --gpus all -d -p 7860:7860 -v $(pwd)/models/:/webui/models -v $(pwd)/embeddings:/webui/models $IMG
126+
# Those `-v` mean mounting your local pre-downloaded model weights, embeddings, extensions( you can also do this for your local textual_inversion_templates, localizations..etc ) to the container, in the same manner.
127+
```
128+
129+
#### c) Run on Kubernetes
130+
131+
Prerequisite:
132+
133+
- You already have a Kubernetes Cluster in place and kube.conf in your machine.
134+
- build the docker images as above step (b), and load it to your K8S cluster.
135+
- Modify the `YOUR-IMAGE-NAME` and `YOUR-LOCAL-PATH` in `docker/k8s-sd-webui.yaml`
136+
137+
```
138+
kubectl apply -f docker/k8s-sd-webui.yaml # Create k8s workload and nodeport service
139+
kubectl get po -l app=stable-diffusion-webui # List the container
140+
#kubectl wait --for=condition=available endpoints/stable-diffusion-webui-service # wait for pod ready, you can CTRL+C to skip it
141+
kubectl get svc stable-diffusion-webui-service # To show the access NodePort port and access it thru K8S NodePort
142+
```
143+
144+
To debug, you can check logs from `kubectl logs -f deploy/stable-diffusion-webui`
145+
117146
### Installation on Windows 10/11 with NVidia-GPUs using release package
118147
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.
119148
2. Run `update.bat`.

compose.yml

Lines changed: 0 additions & 16 deletions
This file was deleted.

Dockerfile renamed to docker/Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM python:3.10-bookworm
1+
FROM python:3.10
22

33
WORKDIR /webui
44

@@ -14,6 +14,6 @@ RUN groupadd --system --gid 1000 webui && \
1414
chown -R webui:webui .
1515
USER 1000:1000
1616

17-
RUN ./webui.sh --prepare-environment-only --skip-torch-cuda-test
17+
RUN ./webui.sh --exit --skip-torch-cuda-test
1818

19-
CMD [ "./webui.sh", "--skip-prepare-environment" ]
19+
CMD [ "./webui.sh", "--skip-prepare-environment", "--listen" ]

docker/compose.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
services:
2+
webui:
3+
build: .
4+
volumes:
5+
- type: bind
6+
source: ./models
7+
target: /webui/models
8+
- type: bind
9+
source: ./outputs
10+
target: /webui/outputs
11+
- type: bind
12+
source: ./extensions
13+
target: /webui/extensions
14+
- type: bind
15+
source: ./embeddings
16+
target: /webui/embeddings
17+
- type: bind
18+
source: ./configs
19+
target: /webui/configs
20+
ports:
21+
- 7860:7860
22+
deploy:
23+
resources:
24+
reservations:
25+
devices:
26+
- driver: nvidia
27+
count: all
28+
capabilities: [gpu]

docker/k8s-sd-webui.yaml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: stable-diffusion-webui
5+
spec:
6+
replicas: 1
7+
selector:
8+
matchLabels:
9+
app: stable-diffusion-webui
10+
template:
11+
metadata:
12+
labels:
13+
app: stable-diffusion-webui
14+
spec:
15+
containers:
16+
- name: stable-diffusion-webui
17+
image: $(YOUR-IMAGE-NAME) # the image name specified when doing `docker build`
18+
ports:
19+
- containerPort: 7860
20+
volumeMounts:
21+
- mountPath: /webui/models
22+
name: models-volume
23+
- mountPath: /webui/outputs
24+
name: image-outputs
25+
- mountPath: /webui/extensions
26+
name: extensions-volume
27+
- mountPath: /webui/embeddings
28+
name: embeddings-volume
29+
resources:
30+
limits:
31+
nvidia.com/gpu: 1 # Adjust according to your needs
32+
readinessProbe:
33+
httpGet:
34+
path: /
35+
port: 7860
36+
initialDelaySeconds: 120
37+
periodSeconds: 30
38+
volumes:
39+
- name: models-volume
40+
hostPath:
41+
path: $(YOUR-LOCAL-PATH)/models # absolute path of pre-download model on the host machine
42+
- name: image-outputs
43+
hostPath:
44+
path: $(YOUR-LOCAL-PATH)/outputs
45+
- name: extensions-volume
46+
hostPath:
47+
path: $(YOUR-LOCAL-PATH)/extensions # absolute path of extensions
48+
- name: embeddings-volume
49+
hostPath:
50+
path: $(YOUR-LOCAL-PATH)/embeddings # absolute path of pre-download embeddings
51+
52+
53+
---
54+
apiVersion: v1
55+
kind: Service
56+
metadata:
57+
name: stable-diffusion-webui-service
58+
spec:
59+
type: NodePort # You can change this to LoadBalancer if needed
60+
ports:
61+
- port: 7860
62+
targetPort: 7860
63+
selector:
64+
app: stable-diffusion-webui

launch.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,14 @@ def main():
3434

3535
launch_utils.startup_timer.record("initial startup")
3636

37-
if args.prepare_environment_only:
38-
print("Setting up requirements wihout starting server as --setup-only flag was passed")
39-
4037
with launch_utils.startup_timer.subcategory("prepare environment"):
4138
if not args.skip_prepare_environment:
4239
prepare_environment()
4340

4441
if args.test_server:
4542
configure_for_tests()
4643

47-
if not args.prepare_environment_only:
48-
start()
44+
start()
4945

5046

5147
if __name__ == "__main__":

modules/cmd_args.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,3 @@
126126
parser.add_argument("--unix-filenames-sanitization", action='store_true', help="allow any symbols except '/' in filenames. May conflict with your browser and file system")
127127
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')
128128
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")
129-
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")

webui-user.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#clone_dir="stable-diffusion-webui"
1111

1212
# Commandline arguments for webui.py, for example: export COMMANDLINE_ARGS="--medvram --opt-split-attention"
13-
export COMMANDLINE_ARGS="--listen"
13+
#export COMMANDLINE_ARGS=""
1414

1515
# python3 executable
1616
#python_cmd="python3"

0 commit comments

Comments
 (0)