Do not store pip cache during docker build #463
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi, thanks for developing the guardrails.
Removing the pip cache in a layer subsequent to the pip install does not reduce image size because the cache stays in the final image. It is more effective and cleaner not using any caching at all.
Adding the option
--no-cache-dir
during pip command reduces the final artifact size for each of the Dockerfiles in the repo, like listed below.Dockerfile
: from 1.68GB to 1.58GB;nemoguardrails/library/jailbreak_detection/Dockerfile
: from 12.3GB to 9.37GB;nemoguardrails/library/jailbreak_detection/Dockerfile-GPU
: from 12.3GB to 9.41GB;nemoguardrails/library/factchecking/align_score/Dockerfile
: from 9.6GB to 7.6GB;For the last three dockerfiles, I reordered the COPY and RUN directives in order to avoid having to download the dependencies every time a single line of code changes.
There could be definitely be more optimizations, such as multi-layer builds.