Skip to content

Commit 79bf79e

Browse files
committed
(docs) add a section on running InvokeAI in the cloud using Docker
1 parent a531652 commit 79bf79e

File tree

1 file changed

+93
-10
lines changed

1 file changed

+93
-10
lines changed

docs/installation/INSTALL_DOCKER.md

Lines changed: 93 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ title: Docker
66

77
!!! warning "For end users"
88

9-
We highly recommend to Install InvokeAI locally using [these instructions](index.md)"
9+
We highly recommend to Install InvokeAI locally using [these instructions](index.md)
1010

1111
!!! tip "For developers"
1212

@@ -16,6 +16,10 @@ title: Docker
1616

1717
For general use, install locally to leverage your machine's GPU.
1818

19+
!!! tip "For running on a cloud instance/service"
20+
21+
Check out the [Running InvokeAI in the cloud with Docker](#running-invokeai-in-the-cloud-with-docker) section below
22+
1923
## Why containers?
2024

2125
They provide a flexible, reliable way to build and deploy InvokeAI. You'll also
@@ -36,7 +40,7 @@ development purposes it's fine. Once you're done with development tasks on your
3640
laptop you can build for the target platform and architecture and deploy to
3741
another environment with NVIDIA GPUs on-premises or in the cloud.
3842

39-
## Installation on a Linux container
43+
## Installation in a Linux container (desktop)
4044

4145
### Prerequisites
4246

@@ -117,12 +121,91 @@ also do so.
117121
./docker-build/run.sh "banana sushi" -Ak_lms -S42 -s10
118122
```
119123

120-
This would generate the legendary "banana sushi" with Seed 42, k_lms Sampler and 10 steps.
124+
This would generate the legendary "banana sushi" with Seed 42, k_lms Sampler and 10 steps.
121125

122126
Find out more about available CLI-Parameters at [features/CLI.md](../../features/CLI/#arguments)
123127

124128
---
125129

130+
## Running InvokeAI in the cloud with Docker
131+
132+
We offer an optimized Ubuntu-based image that has been well-tested in cloud deployments. Note: it also works well locally on Linux x86_64 systems with an Nvidia GPU. It *may* also work on Windows under WSL2 and on Intel Mac (not tested).
133+
134+
An advantage of this method is that it does not need any local setup or additional dependencies.
135+
136+
See the `docker-build/Dockerfile.cloud` file to familizarize yourself with the image's content.
137+
138+
### Prerequisites
139+
140+
- a `docker` runtime
141+
- `make` (optional but helps for convenience)
142+
- Huggingface token to download models, or an existing InvokeAI runtime directory from a previous installation
143+
144+
Neither local Python nor any dependencies are required. If you don't have `make` (part of `build-essentials` on Ubuntu), or do not wish to install it, the commands from the `docker-build/Makefile` are readily adaptable to be executed directly.
145+
146+
### Building and running the image locally
147+
148+
1. Clone this repo and `cd docker-build`
149+
1. `make build` - this will build the image. (This does *not* require a GPU-capable system).
150+
1. _(skip this step if you already have a complete InvokeAI runtime directory)_
151+
- `make configure` (This does *not* require a GPU-capable system)
152+
- this will create a local cache of models and configs (a.k.a the _runtime dir_)
153+
- enter your Huggingface token when prompted
154+
1. `make web`
155+
1. Open the `http://localhost:9090` URL in your browser, and enjoy the banana sushi!
156+
157+
To use InvokeAI on the cli, run `make cli`. To open a Bash shell in the container for arbitraty advanced use, `make shell`.
158+
159+
#### Building and running without `make`
160+
161+
(Feel free to adapt paths such as `${HOME}/invokeai` to your liking, and modify the CLI arguments as necessary).
162+
163+
!!! example "Build the image and configure the runtime directory"
164+
```Shell
165+
cd docker-build
166+
167+
DOCKER_BUILDKIT=1 docker build -t local/invokeai:latest -f Dockerfile.cloud ..
168+
169+
docker run --rm -it -v ${HOME}/invokeai:/mnt/invokeai local/invokeai:latest -c "python scripts/configure_invokeai.py"
170+
```
171+
172+
!!! example "Run the web server"
173+
```Shell
174+
docker run --runtime=nvidia --gpus=all --rm -it -v ${HOME}/invokeai:/mnt/invokeai -p9090:9090 local/invokeai:latest
175+
```
176+
177+
Access the Web UI at http://localhost:9090
178+
179+
!!! example "Run the InvokeAI interactive CLI"
180+
```
181+
docker run --runtime=nvidia --gpus=all --rm -it -v ${HOME}/invokeai:/mnt/invokeai local/invokeai:latest -c "python scripts/invoke.py"
182+
```
183+
184+
### Running the image in the cloud
185+
186+
This image works anywhere you can run a container with a mounted Docker volume. You may either build this image on a cloud instance, or build and push it to your Docker registry. To manually run this on a cloud instance (such as AWS EC2, GCP or Azure VM):
187+
188+
1. build this image either in the cloud (you'll need to pull the repo), or locally
189+
1. `docker tag` it as `your-registry/invokeai` and push to your registry (i.e. Dockerhub)
190+
1. `docker pull` it on your cloud instance
191+
1. configure the runtime directory as per above example, using `docker run ... configure_invokeai.py` script
192+
1. use either one of the `docker run` commands above, substituting the image name for your own image.
193+
194+
To run this on Runpod, please refer to the following Runpod template: https://www.runpod.io/console/gpu-secure-cloud?template=vm19ukkycf (you need a Runpod subscription). When launching the template, feel free to set the image to pull your own build.
195+
196+
The template's `README` provides ample detail, but at a high level, the process is as follows:
197+
198+
1. create a pod using this Docker image
199+
1. ensure the pod has an `INVOKEAI_ROOT=<path_to_your_persistent_volume>` environment variable, and that it corresponds to the path to your pod's persistent volume mount
200+
1. Run the pod with `sleep infinity` as the Docker command
201+
1. Use Runpod basic SSH to connect to the pod, and run `python scripts/configure_invokeai.py` script
202+
1. Stop the pod, and change the Docker command to `python scripts/invoke.py --web --host 0.0.0.0`
203+
1. Run the pod again, connect to your pod on HTTP port 9090, and enjoy the banana sushi!
204+
205+
Running on other cloud providers such as Vast.ai will likely work in a similar fashion.
206+
207+
---
208+
126209
!!! warning "Deprecated"
127210

128211
From here on you will find the the previous Docker-Docs, which will still
@@ -135,12 +218,12 @@ also do so.
135218
If you're on a **Linux container** the `invoke` script is **automatically
136219
started** and the output dir set to the Docker volume you created earlier.
137220

138-
If you're **directly on macOS follow these startup instructions**.
221+
If you're **directly on macOS follow these startup instructions**.
139222
With the Conda environment activated (`conda activate ldm`), run the interactive
140223
interface that combines the functionality of the original scripts `txt2img` and
141-
`img2img`:
224+
`img2img`:
142225
Use the more accurate but VRAM-intensive full precision math because
143-
half-precision requires autocast and won't work.
226+
half-precision requires autocast and won't work.
144227
By default the images are saved in `outputs/img-samples/`.
145228

146229
```Shell
@@ -157,8 +240,8 @@ invoke> q
157240
### Text to Image
158241

159242
For quick (but bad) image results test with 5 steps (default 50) and 1 sample
160-
image. This will let you know that everything is set up correctly.
161-
Then increase steps to 100 or more for good (but slower) results.
243+
image. This will let you know that everything is set up correctly.
244+
Then increase steps to 100 or more for good (but slower) results.
162245
The prompt can be in quotes or not.
163246

164247
```Shell
@@ -172,8 +255,8 @@ You'll need to experiment to see if face restoration is making it better or
172255
worse for your specific prompt.
173256

174257
If you're on a container the output is set to the Docker volume. You can copy it
175-
wherever you want.
176-
You can download it from the Docker Desktop app, Volumes, my-vol, data.
258+
wherever you want.
259+
You can download it from the Docker Desktop app, Volumes, my-vol, data.
177260
Or you can copy it from your Mac terminal. Keep in mind `docker cp` can't expand
178261
`*.png` so you'll need to specify the image file name.
179262

0 commit comments

Comments
 (0)