Simplify docker compose setup

This commit is contained in:
Wilson E. Alvarez 2023-10-30 16:53:02 -04:00 committed by Kent Keirsey
parent ea4ef042f3
commit d1d8ee71fc
4 changed files with 44 additions and 35 deletions

View File

@ -23,7 +23,7 @@ This is done via Docker Desktop preferences
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: 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 a. the desired location of the InvokeAI runtime directory, or
b. an existing, v3.0.0 compatible runtime directory. b. an existing, v3.0.0 compatible runtime directory.
1. `docker compose up` 1. Execute `run.sh`
The image will be built automatically if needed. The image will be built automatically if needed.
@ -39,7 +39,7 @@ The Docker daemon on the system must be already set up to use the GPU. In case o
## Customize ## 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 `docker compose up`, your custom values will be used. 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. You can also set these values in `docker-compose.yml` directly, but `.env` will help avoid conflicts when code is updated.

View File

@ -1,11 +0,0 @@
#!/usr/bin/env bash
set -e
build_args=""
[[ -f ".env" ]] && build_args=$(awk '$1 ~ /\=[^$]/ {print "--build-arg " $0 " "}' .env)
echo "docker compose build args:"
echo $build_args
docker compose build $build_args

View File

@ -2,23 +2,8 @@
version: '3.8' version: '3.8'
services: x-invokeai: &invokeai
invokeai:
image: "local/invokeai:latest" image: "local/invokeai:latest"
# edit below to run on a container runtime other than nvidia-container-runtime.
# not yet tested with rocm/AMD GPUs
# Comment out the "deploy" section to run on CPU only
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: 1
capabilities: [gpu]
# For AMD support, comment out the deploy section above and uncomment the devices section below:
#devices:
# - /dev/kfd:/dev/kfd
# - /dev/dri:/dev/dri
build: build:
context: .. context: ..
dockerfile: docker/Dockerfile dockerfile: docker/Dockerfile
@ -50,3 +35,23 @@ services:
# - | # - |
# invokeai-model-install --yes --default-only --config_file ${INVOKEAI_ROOT}/config_custom.yaml # invokeai-model-install --yes --default-only --config_file ${INVOKEAI_ROOT}/config_custom.yaml
# invokeai-nodes-web --host 0.0.0.0 # invokeai-nodes-web --host 0.0.0.0
services:
invokeai-cpu:
<<: *invokeai
invokeai-nvidia:
<<: *invokeai
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: 1
capabilities: [gpu]
invokeai-rocm:
<<: *invokeai
devices:
- /dev/kfd:/dev/kfd
- /dev/dri:/dev/dri

View File

@ -1,11 +1,26 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -e set -e
# This script is provided for backwards compatibility with the old docker setup. run() {
# it doesn't do much aside from wrapping the usual docker compose CLI. local scriptdir=$(dirname "${BASH_SOURCE[0]}")
cd "$scriptdir" || exit 1
SCRIPTDIR=$(dirname "${BASH_SOURCE[0]}") local build_args=""
cd "$SCRIPTDIR" || exit 1 local service_name="invokeai-cpu"
docker compose up -d [[ -f ".env" ]] &&
docker compose logs -f build_args=$(awk '$1 ~ /=[^$]/ {print "--build-arg " $0 " "}' .env) &&
service_name="invokeai-$(awk -F '=' '/GPU_DRIVER/ {print $2}' .env)"
printf "%s\n" "docker compose build args:"
printf "%s\n" "$build_args"
docker compose build $build_args
unset build_args
printf "%s\n" "starting service $service_name"
docker compose up -d $service_name
docker compose logs -f
}
run