diff --git a/docker/README.md b/docker/README.md index 4291ece25f..567ce6832d 100644 --- a/docker/README.md +++ b/docker/README.md @@ -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: a. the desired location of the InvokeAI runtime directory, or 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. @@ -39,7 +39,7 @@ The Docker daemon on the system must be already set up to use the GPU. In case o ## 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. diff --git a/docker/build.sh b/docker/build.sh deleted file mode 100755 index 3b3875c15c..0000000000 --- a/docker/build.sh +++ /dev/null @@ -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 diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index f7e92d6bf5..b6a965d120 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -2,23 +2,8 @@ version: '3.8' -services: - invokeai: +x-invokeai: &invokeai 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: context: .. dockerfile: docker/Dockerfile @@ -50,3 +35,27 @@ services: # - | # invokeai-model-install --yes --default-only --config_file ${INVOKEAI_ROOT}/config_custom.yaml # invokeai-nodes-web --host 0.0.0.0 + +services: + invokeai-nvidia: + <<: *invokeai + deploy: + resources: + reservations: + devices: + - driver: nvidia + count: 1 + capabilities: [gpu] + + invokeai-cpu: + <<: *invokeai + profiles: + - cpu + + invokeai-rocm: + <<: *invokeai + devices: + - /dev/kfd:/dev/kfd + - /dev/dri:/dev/dri + profiles: + - rocm diff --git a/docker/run.sh b/docker/run.sh index 4b595b06df..4fe1bf4237 100755 --- a/docker/run.sh +++ b/docker/run.sh @@ -1,11 +1,28 @@ #!/usr/bin/env bash set -e -# This script is provided for backwards compatibility with the old docker setup. -# it doesn't do much aside from wrapping the usual docker compose CLI. +run() { + local scriptdir=$(dirname "${BASH_SOURCE[0]}") + cd "$scriptdir" || exit 1 -SCRIPTDIR=$(dirname "${BASH_SOURCE[0]}") -cd "$SCRIPTDIR" || exit 1 + local build_args="" + local profile="" -docker compose up -d -docker compose logs -f + [[ -f ".env" ]] && + build_args=$(awk '$1 ~ /=[^$]/ && $0 !~ /^#/ {print "--build-arg " $0 " "}' .env) && + profile="$(awk -F '=' '/GPU_DRIVER/ {print $2}' .env)" + + local service_name="invokeai-$profile" + + 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 --profile "$profile" up -d "$service_name" + docker compose logs -f +} + +run