Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5897e51

Browse files
authored
Debloat-docker (#1612)
* debloat Dockerfile - less options more but more userfriendly - better Entrypoint to simulate CLI usage - without command the container still starts the web-host * debloat build.sh * better syntax in run.sh * update Docker docs - fix description of VOLUMENAME - update run script example to reflect new entrypoint
1 parent f43b767 commit 5897e51

File tree

4 files changed

+27
-46
lines changed

4 files changed

+27
-46
lines changed

docker-build/Dockerfile

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,17 @@ RUN apt-get update \
1818
&& apt-get clean \
1919
&& rm -rf /var/lib/apt/lists/*
2020

21-
ARG PIP_REQUIREMENTS=requirements-lin-cuda.txt
22-
ARG PROJECT_NAME=invokeai
23-
ARG INVOKEAI_ROOT=/data
24-
ENV INVOKEAI_ROOT=${INVOKEAI_ROOT}
25-
2621
# set workdir and copy sources
27-
WORKDIR /${PROJECT_NAME}
28-
COPY . .
22+
WORKDIR /invokeai
23+
ARG PIP_REQUIREMENTS=requirements-lin-cuda.txt
24+
COPY . ./environments-and-requirements/${PIP_REQUIREMENTS} ./
2925

3026
# install requirements and link outputs folder
31-
RUN cp \
32-
./environments-and-requirements/${PIP_REQUIREMENTS} \
33-
${PIP_REQUIREMENTS} \
34-
&& pip install \
35-
--no-cache-dir \
36-
-r ${PIP_REQUIREMENTS} \
37-
&& ln -sf /data/outputs /${PROJECT_NAME}/outputs
27+
RUN pip install \
28+
--no-cache-dir \
29+
-r ${PIP_REQUIREMENTS}
3830

39-
# set Entrypoint and default CMD
40-
ENTRYPOINT [ "python3" ]
41-
CMD [ "scripts/invoke.py", "--web", "--host", "0.0.0.0" ]
31+
# set Environment, Entrypoint and default CMD
32+
ENV INVOKEAI_ROOT /data
33+
ENTRYPOINT [ "python3", "scripts/invoke.py", "--outdir=/data/outputs" ]
34+
CMD [ "--web", "--host=0.0.0.0" ]

docker-build/build.sh

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
#!/usr/bin/env bash
22
set -e
3-
# IMPORTANT: You need to have a token on huggingface.co to be able to download the checkpoint!!!
4-
# configure values by using env when executing build.sh
5-
# f.e. env ARCH=aarch64 GITHUB_INVOKE_AI=https://github.com/yourname/yourfork.git ./build.sh
63

7-
source ./docker-build/env.sh || echo "please run from repository root" || exit 1
4+
# IMPORTANT: You need to have a token on huggingface.co to be able to download the checkpoints!!!
5+
# configure values by using env when executing build.sh f.e. `env ARCH=aarch64 ./build.sh`
6+
7+
source ./docker-build/env.sh \
8+
|| echo "please execute docker-build/build.sh from repository root" \
9+
|| exit 1
810

911
pip_requirements=${PIP_REQUIREMENTS:-requirements-lin-cuda.txt}
1012
dockerfile=${INVOKE_DOCKERFILE:-docker-build/Dockerfile}
@@ -13,28 +15,14 @@ dockerfile=${INVOKE_DOCKERFILE:-docker-build/Dockerfile}
1315
echo "You are using these values:"
1416
echo -e "Dockerfile:\t\t ${dockerfile}"
1517
echo -e "requirements:\t\t ${pip_requirements}"
16-
echo -e "project_name:\t\t ${project_name}"
1718
echo -e "volumename:\t\t ${volumename}"
1819
echo -e "arch:\t\t\t ${arch}"
1920
echo -e "platform:\t\t ${platform}"
2021
echo -e "invokeai_tag:\t\t ${invokeai_tag}\n"
2122

22-
_runAlpine() {
23-
docker run \
24-
--rm \
25-
--interactive \
26-
--tty \
27-
--mount source="$volumename",target=/data \
28-
--workdir /data \
29-
alpine "$@"
30-
}
31-
32-
_checkVolumeContent() {
33-
_runAlpine ls -lhA /data/models
34-
}
35-
3623
if [[ -n "$(docker volume ls -f name="${volumename}" -q)" ]]; then
3724
echo "Volume already exists"
25+
echo
3826
else
3927
echo -n "createing docker volume "
4028
docker volume create "${volumename}"
@@ -44,7 +32,6 @@ fi
4432
docker build \
4533
--platform="${platform}" \
4634
--tag="${invokeai_tag}" \
47-
--build-arg="PROJECT_NAME=${project_name}" \
4835
--build-arg="PIP_REQUIREMENTS=${pip_requirements}" \
4936
--file="${dockerfile}" \
5037
.
@@ -57,5 +44,6 @@ docker run \
5744
--mount="source=$volumename,target=/data" \
5845
--mount="type=bind,source=$HOME/.huggingface,target=/root/.huggingface" \
5946
--env="HUGGINGFACE_TOKEN=${HUGGINGFACE_TOKEN}" \
47+
--entrypoint="python3" \
6048
"${invokeai_tag}" \
6149
scripts/configure_invokeai.py --yes

docker-build/run.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ docker run \
77
--interactive \
88
--tty \
99
--rm \
10-
--platform "$platform" \
11-
--name "$project_name" \
12-
--hostname "$project_name" \
13-
--mount source="$volumename",target=/data \
14-
--publish 9090:9090 \
10+
--platform="$platform" \
11+
--name="$project_name" \
12+
--hostname="$project_name" \
13+
--mount="source=$volumename,target=/data" \
14+
--publish=9090:9090 \
1515
"$invokeai_tag" ${1:+$@}

docs/installation/INSTALL_DOCKER.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ Some Suggestions of variables you may want to change besides the Token:
7878
| -------------------- | ----------------------------- | -------------------------------------------------------------------------------------------- |
7979
| `HUGGINGFACE_TOKEN` | No default, but **required**! | This is the only **required** variable, without it you can't download the huggingface models |
8080
| `PROJECT_NAME` | `invokeai` | affects the project folder, tag- and volume name |
81-
| `VOLUMENAME` | `${PROJECT_NAME}_data` | affects the project folder, tag- and volume name |
81+
| `VOLUMENAME` | `${PROJECT_NAME}_data` | Name of the Docker Volume where model files will be stored |
8282
| `ARCH` | `x86_64` | can be changed to f.e. aarch64 if you are using a ARM based CPU |
8383
| `INVOKEAI_TAG` | `${PROJECT_NAME}:${ARCH}` | the Container Repository / Tag which will be used |
8484
| `PIP_REQUIREMENTS` | `requirements-lin-cuda.txt` | the requirements file to use (from `environments-and-requirements`) |
@@ -111,13 +111,13 @@ When used without arguments, the container will start the webserver and provide
111111
you the link to open it. But if you want to use some other parameters you can
112112
also do so.
113113

114-
!!! example ""
114+
!!! example "run script example"
115115

116116
```bash
117-
./docker-build/run.sh scripts/invoke.py
117+
./docker-build/run.sh "banana sushi" -Ak_lms -S42 -s10
118118
```
119119

120-
This would start the CLI instead of the default command that starts the webserver.
120+
This would generate the legendary "banana sushi" with Seed 42, k_lms Sampler and 10 steps.
121121

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

0 commit comments

Comments
 (0)