From 88c1af969f434e5659ad851eee4e8e2b3b2c8cb1 Mon Sep 17 00:00:00 2001 From: Eugene Brodsky Date: Sat, 23 Dec 2023 03:10:18 -0500 Subject: [PATCH] update docker setup, improve docs, fix variable value Fixes #5336 --- docker/.env.sample | 2 +- docker/README.md | 18 ++++++++++++++---- docker/run.sh | 16 ++++++++++------ 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/docker/.env.sample b/docker/.env.sample index 98ad307c04..a9be746d63 100644 --- a/docker/.env.sample +++ b/docker/.env.sample @@ -11,5 +11,5 @@ INVOKEAI_ROOT= # HUGGING_FACE_HUB_TOKEN= ## optional variables specific to the docker setup. -# GPU_DRIVER=cuda # or rocm +# GPU_DRIVER=nvidia #| rocm # CONTAINER_UID=1000 diff --git a/docker/README.md b/docker/README.md index 567ce6832d..c2e26bb9e4 100644 --- a/docker/README.md +++ b/docker/README.md @@ -1,6 +1,14 @@ # InvokeAI Containerized -All commands are to be run from the `docker` directory: `cd docker` +All commands should be run within the `docker` directory: `cd docker` + +## Quickstart :rocket: + +On a known working Linux+Docker+CUDA (Nvidia) system, execute `./run.sh` in this directory. It will take a few minutes - depending on your internet speed - to install the core models. Once the application starts up, open `http://localhost:9090` in your browser to Invoke! + +For more configuration options (using an AMD GPU, custom root directory location, etc): read on. + +## Detailed setup #### Linux @@ -18,7 +26,7 @@ All commands are to be run from the `docker` directory: `cd docker` This is done via Docker Desktop preferences -## Quickstart +### Configure Invoke environment 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: a. the desired location of the InvokeAI runtime directory, or @@ -37,19 +45,21 @@ The runtime directory (holding models and outputs) will be created in the locati 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 documentation for the most up-to-date instructions for using your GPU with Docker. +To use an AMD GPU, set `GPU_DRIVER=rocm` in your `.env` file. + ## Customize 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. You can also set these values in `docker-compose.yml` directly, but `.env` will help avoid conflicts when code is updated. -Example (values are optional, but setting `INVOKEAI_ROOT` is highly recommended): +Values are optional, but setting `INVOKEAI_ROOT` is highly recommended. The default is `~/invokeai`. Example: ```bash INVOKEAI_ROOT=/Volumes/WorkDrive/invokeai HUGGINGFACE_TOKEN=the_actual_token CONTAINER_UID=1000 -GPU_DRIVER=cuda +GPU_DRIVER=nvidia ``` Any environment variables supported by InvokeAI can be set here - please see the [Configuration docs](https://invoke-ai.github.io/InvokeAI/features/CONFIGURATION/) for further detail. diff --git a/docker/run.sh b/docker/run.sh index 4fe1bf4237..409df508dd 100755 --- a/docker/run.sh +++ b/docker/run.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -set -e +set -e -o pipefail run() { local scriptdir=$(dirname "${BASH_SOURCE[0]}") @@ -8,14 +8,18 @@ run() { local build_args="" local profile="" - [[ -f ".env" ]] && - build_args=$(awk '$1 ~ /=[^$]/ && $0 !~ /^#/ {print "--build-arg " $0 " "}' .env) && - profile="$(awk -F '=' '/GPU_DRIVER/ {print $2}' .env)" + touch .env + build_args=$(awk '$1 ~ /=[^$]/ && $0 !~ /^#/ {print "--build-arg " $0 " "}' .env) && + profile="$(awk -F '=' '/GPU_DRIVER/ {print $2}' .env)" + + [[ -z "$profile" ]] && profile="nvidia" local service_name="invokeai-$profile" - printf "%s\n" "docker compose build args:" - printf "%s\n" "$build_args" + if [[ ! -z "$build_args" ]]; then + printf "%s\n" "docker compose build args:" + printf "%s\n" "$build_args" + fi docker compose build $build_args unset build_args