2024-06-24 20:51:06 +00:00
# Invoke in Docker
2023-06-25 20:03:02 +00:00
2024-07-23 16:00:09 +00:00
First things first:
- Ensure that Docker can use your [NVIDIA][nvidia docker docs] or [AMD][amd docker docs] GPU.
- This document assumes a Linux system, but should work similarly under Windows with WSL2.
2024-06-24 20:51:06 +00:00
- We don't recommend running Invoke in Docker on macOS at this time. It works, but very slowly.
2023-12-23 08:10:18 +00:00
2024-07-23 16:00:09 +00:00
## Quickstart
2023-12-23 08:10:18 +00:00
2024-07-23 16:00:09 +00:00
No `docker compose` , no persistence, single command, using the official images:
2023-12-23 08:10:18 +00:00
2024-07-23 16:00:09 +00:00
**CUDA (NVIDIA GPU):**
2023-12-23 08:10:18 +00:00
2024-06-24 20:51:06 +00:00
```bash
docker run --runtime=nvidia --gpus=all --publish 9090:9090 ghcr.io/invoke-ai/invokeai
```
2024-07-23 16:00:09 +00:00
**ROCm (AMD GPU):**
2024-06-24 20:51:06 +00:00
```bash
docker run --device /dev/kfd --device /dev/dri --publish 9090:9090 ghcr.io/invoke-ai/invokeai:main-rocm
```
Open `http://localhost:9090` in your browser once the container finishes booting, install some models, and generate away!
2024-07-23 16:00:09 +00:00
### Data persistence
To persist your generated images and downloaded models outside of the container, add a `--volume/-v` flag to the above command, e.g.:
```bash
docker run --volume /some/local/path:/invokeai {...etc...}
```
`/some/local/path/invokeai` will contain all your data.
It can *usually* be reused between different installs of Invoke. Tread with caution and read the release notes!
2024-06-24 20:51:06 +00:00
## Customize the container
2024-07-23 16:00:09 +00:00
The included `run.sh` script is a convenience wrapper around `docker compose` . It can be helpful for passing additional build arguments to `docker compose` . Alternatively, the familiar `docker compose` commands work just as well.
2024-06-24 20:51:06 +00:00
```bash
cd docker
cp .env.sample .env
# edit .env to your liking if you need to; it is well commented.
./run.sh
```
It will take a few minutes to build the image the first time. Once the application starts up, open `http://localhost:9090` in your browser to invoke!
2024-07-23 16:00:09 +00:00
>[!TIP]
>When using the `run.sh` script, the container will continue running after Ctrl+C. To shut it down, use the `docker compose down` command.
2024-06-24 20:51:06 +00:00
## Docker setup in detail
2023-06-25 20:03:02 +00:00
2023-06-26 06:12:11 +00:00
#### Linux
2023-06-25 20:03:02 +00:00
2024-07-23 16:00:09 +00:00
1. Ensure buildkit is enabled in the Docker daemon settings (`/etc/docker/daemon.json`)
2023-10-19 15:25:47 +00:00
2. Install the `docker compose` plugin using your package manager, or follow a [tutorial ](https://docs.docker.com/compose/install/linux/#install-using-the-repository ).
2024-06-24 20:51:06 +00:00
- The deprecated `docker-compose` (hyphenated) CLI probably won't work. Update to a recent version.
2023-06-25 20:03:02 +00:00
3. Ensure docker daemon is able to access the GPU.
2024-06-24 20:51:06 +00:00
- [NVIDIA docs ](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html )
- [AMD docs ](https://rocm.docs.amd.com/projects/install-on-linux/en/latest/how-to/docker.html )
2023-06-25 20:03:02 +00:00
2023-06-26 06:12:11 +00:00
#### macOS
2023-06-25 20:03:02 +00:00
2024-06-24 20:51:06 +00:00
> [!TIP]
> You'll be better off installing Invoke directly on your system, because Docker can not use the GPU on macOS.
If you are still reading:
2023-06-25 20:03:02 +00:00
1. Ensure Docker has at least 16GB RAM
2. Enable VirtioFS for file sharing
2023-06-26 06:12:11 +00:00
3. Enable `docker compose` V2 support
2023-06-25 20:03:02 +00:00
2024-06-24 20:51:06 +00:00
This is done via Docker Desktop preferences.
2023-06-25 20:03:02 +00:00
2024-06-24 20:51:06 +00:00
### Configure the Invoke Environment
2023-06-25 20:03:02 +00:00
2024-06-24 20:51:06 +00:00
1. Make a copy of `.env.sample` and name it `.env` (`cp .env.sample .env` (Mac/Linux) or `copy example.env .env` (Windows)). Make changes as necessary. Set `INVOKEAI_ROOT` to an absolute path to the desired location of the InvokeAI runtime directory. It may be an existing directory from a previous installation (post 4.0.0).
2023-10-30 20:53:02 +00:00
1. Execute `run.sh`
2023-06-25 20:03:02 +00:00
The image will be built automatically if needed.
2024-06-24 20:51:06 +00:00
The runtime directory (holding models and outputs) will be created in the location specified by `INVOKEAI_ROOT` . The default location is `~/invokeai` . Navigate to the Model Manager tab and install some models before generating.
2023-06-25 20:03:02 +00:00
### Use a GPU
- Linux is *recommended* for GPU support in Docker.
- WSL2 is *required* for Windows.
- only `x86_64` architecture is supported.
2024-06-24 20:51:06 +00:00
The Docker daemon on the system must be already set up to use the GPU. In case of Linux, this involves installing `nvidia-docker-runtime` and configuring the `nvidia` runtime as default. Steps will be different for AMD. Please see Docker/NVIDIA/AMD documentation for the most up-to-date instructions for using your GPU with Docker.
2023-06-25 20:03:02 +00:00
2024-06-24 20:51:06 +00:00
To use an AMD GPU, set `GPU_DRIVER=rocm` in your `.env` file before running `./run.sh` .
2023-12-23 08:10:18 +00:00
2023-06-25 20:03:02 +00:00
## Customize
2023-10-30 20:53:02 +00:00
Check the `.env.sample` file. It contains some environment variables for running in Docker. Copy it, name it `.env` , and fill it in with your own values. Next time you run `run.sh` , your custom values will be used.
2023-06-25 20:03:02 +00:00
2023-10-19 15:25:47 +00:00
You can also set these values in `docker-compose.yml` directly, but `.env` will help avoid conflicts when code is updated.
2023-06-25 20:03:02 +00:00
2023-12-23 08:10:18 +00:00
Values are optional, but setting `INVOKEAI_ROOT` is highly recommended. The default is `~/invokeai` . Example:
2023-06-25 20:03:02 +00:00
2023-10-19 15:25:47 +00:00
```bash
2023-06-26 06:12:11 +00:00
INVOKEAI_ROOT=/Volumes/WorkDrive/invokeai
2023-06-25 20:03:02 +00:00
HUGGINGFACE_TOKEN=the_actual_token
CONTAINER_UID=1000
2024-06-24 20:51:06 +00:00
GPU_DRIVER=cuda
2023-06-25 20:03:02 +00:00
```
2024-06-24 20:51:06 +00:00
Any environment variables supported by InvokeAI can be set here. See the [Configuration docs ](https://invoke-ai.github.io/InvokeAI/features/CONFIGURATION/ ) for further detail.
2023-10-19 15:25:47 +00:00
2024-07-23 16:00:09 +00:00
---
2023-06-25 20:03:02 +00:00
2024-07-23 16:00:09 +00:00
[nvidia docker docs]: https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html
[amd docker docs]: https://rocm.docs.amd.com/projects/install-on-linux/en/latest/how-to/docker.html