Skip to content

Commit 5a0fa91

Browse files
committed
update Dockerfile according to comments and move to separated folder
Signed-off-by: Peter Pan <[email protected]>
1 parent 5070021 commit 5a0fa91

File tree

8 files changed

+90
-15
lines changed

8 files changed

+90
-15
lines changed

.dockerignore

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

README.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,41 @@ 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=v1.10.0
123+
docker build -t stable-diffusion-webui:${TAG} -f docker/Dockerfile .
124+
docker run --gpus all -d -p 7860:7860 stable-diffusion-webui:${TAG}
125+
# If you have already downloaded the model weight locally, you can mount it into container (add `-v $(your-local-model-path)/models/:/webui/models` to above `docker run` command before image name.)
126+
```
127+
128+
#### c) Run on Kubernetes
129+
130+
Prerequisite:
131+
132+
- You already have a Kubernetes Cluster in place and kube.conf in your machine.
133+
- build the docker images as above step (b), and load it to your K8S cluster.
134+
- Modify the `YOUR-IMAGE-NAME` and `YOUR-LOCAL-PATH` in `docker/k8s-sd-webui.yaml`
135+
136+
```
137+
kubectl apply -f docker/k8s-sd-webui.yaml # Create k8s workload and nodeport service
138+
kubectl get po -l app=stable-diffusion-webui # list the container
139+
#kubectl wait --for=condition=available endpoints/stable-diffusion-webui-service # wait for pod ready, you can CTRL+C to skip it
140+
```
141+
142+
To debug, you can check logs from `kubectl logs -f deploy/stable-diffusion-webui`
143+
117144
### Installation on Windows 10/11 with NVidia-GPUs using release package
118145
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.
119146
2. Run `update.bat`.

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" ]

compose.yml renamed to docker/compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
services:
22
webui:
3-
build: .
3+
build: ../
44
volumes:
55
- type: bind
66
source: ./models
@@ -13,4 +13,4 @@ services:
1313
devices:
1414
- driver: nvidia
1515
count: all
16-
capabilities: [gpu]
16+
capabilities: [gpu]

docker/k8s-sd-webui.yaml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
resources:
24+
limits:
25+
nvidia.com/gpu: 1 # Adjust according to your needs
26+
readinessProbe:
27+
httpGet:
28+
path: /
29+
port: 7860
30+
initialDelaySeconds: 120
31+
periodSeconds: 30
32+
volumes:
33+
- name: models-volume
34+
hostPath:
35+
path: $(YOUR-LOCAL-PATH)/models # absolute pre-download model path on the host machine
36+
37+
---
38+
apiVersion: v1
39+
kind: Service
40+
metadata:
41+
name: stable-diffusion-webui-service
42+
spec:
43+
type: NodePort # You can change this to LoadBalancer if needed
44+
ports:
45+
- port: 7860
46+
targetPort: 7860
47+
selector:
48+
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)