目前仅支持 Node.js 应用;generate 命令必须提供 API Key,optimize 用 AI 也需提供;macOS 必须用 Homebrew 安装,二进制未公证;API Key 不保存,每次使用都要重新传入
dockershrink
duaraghav8MPL-2.0更新放缓用 AI 助手分析应用 Dockerfile 和镜像层,自动给出精简方案来缩小镜像体积,省去手动排查冗余依赖和构建步骤的麻烦。
AI Assistant that reduces the size of your application's Docker Image
brew install duaraghav8/tap/dockershrinkREADME 未说明;工具为独立二进制,本地需 Docker 守护进程运行(开发前提),AI 功能需可访问的 OpenAI 兼容端点
用 AI 和算法分析自动瘦身 Node.js 应用的 Docker 镜像,生成或优化 Dockerfile
用 AI 助手分析应用 Dockerfile 和镜像层,自动给出精简方案来缩小镜像体积,省去手动排查冗余依赖和构建步骤的麻烦。
核心能力
- 自动应用多阶段构建和 alpine 等轻量基础镜像
- 生成新的 Dockerfile 与 .dockerignore
- 优化已有镜像定义,去除冗余层
- 兼容任意 OpenAI 格式 API 端点,含 Bedrock 与 Ollama
- 支持 --debug 输出排查日志
容易踩的坑
- v0.1.7最新正式版2025-01-24 · 2025-01-24 00:36 UTC
- v0.1.6Version 0.1.62025-01-21 · 2025-01-21 15:58 UTC
查看更新说明
What's Changed
- Feat: Add generate command to dockershrink by @Ilhan-Personal in https://github.com/duaraghav8/dockershrink/pull/28
New Contributors
- @Ilhan-Personal made their first contribution in https://github.com/duaraghav8/dockershrink/pull/28
Full Changelog: https://github.com/duaraghav8/dockershrink/compare/v0.1.5...v0.1.6
- v0.1.52024-12-29 · 2024-12-29 16:01 UTC
查看更新说明
What's Changed
- Report a .dockerignore modification under "Actions taken" by @sahinfalcon in https://github.com/duaraghav8/dockershrink/pull/18
New Contributors
- @sahinfalcon made their first contribution in https://github.com/duaraghav8/dockershrink/pull/18
Full Changelog: https://github.com/duaraghav8/dockershrink/compare/v0.1.4...v0.1.5
- v0.1.42024-12-10 · 2024-12-10 14:07 UTC
查看更新说明
What's Changed
- Handle exception in case of no COPY statements in Dockerfile by @duaraghav8 in https://github.com/duaraghav8/dockershrink/commit/9ecd32e7df04c6c7e0a913bce203ac41bbdda6dc
- enable verbose mode to output failure stack traces by @duaraghav8 in https://github.com/duaraghav8/dockershrink/pull/4
- Add issue templates by @duaraghav8 in https://github.com/duaraghav8/dockershrink/pull/5
Full Changelog: https://github.com/duaraghav8/dockershrink/compare/v0.1.3...v0.1.4
- v0.1.3Release version 0.1.32024-12-03 · 2024-12-03 13:27 UTC
这个版本没有写更新说明。
用户点评
登录用户的真实使用记录,可按版本和硬件筛选还没有人点评。第一个说出真实体验的人最有价值。
DockerShrink
Talk to us on Slack | Vote for Feature Requests
Dockershrink is an AI-powered Commandline Tool that helps you reduce the size of your Docker images

It combines the power of algorithmic analysis with Generative AI to apply state-of-the-art optimizations to your Image configurations :brain:
Dockershrink can automatically apply techniques like Multi-Stage builds, switching to Lighter base images like alpine and running dependency checks. PLUS a lot more is on the roadmap :rocket:
Currently, the tool only supports NodeJS applications.
It can:
- Generate optimized Docker image defintions (Dockerfile and .dockerignore) for new projects
- Optimize existing image definition by including best practices to avoid bloat
[!IMPORTANT] Dockershrink is BETA software.
You can provide your feedback by creating an Issue in this repository.
Why does dockershrink exist?
Every org using containers in development or production environments understands the pain of managing hundreds or even thousands of bloated Docker images in their infrastructure.
High data storage and transfer costs, long build times, underprodctive developers - we've seen it all.
The issue becomes even more painful and costly with interpreted languages such as Nodejs & Python. Apps written in these languages need to pack the interpreters and all their dependencies inside their container images, significantly increasing their size.
But not everyone realizes that by just implementing some basic techniques, they can reduce the size of a 1GB Docker image down to as little as 100 MB!
(I also made a video on how to do this.)
Imagine the costs saved in storage & data transfer, decrease in build times AND the productivity gains for developers :exploding_head:
Dockershrink aims to automatically apply advanced optimization techniques so engineers don't have to waste time on it and the organization still saves :moneybag:!
You're welcome :wink:
Installation
Dockershrink is shipped as a stand-alone binary.
You can either download it from the Releases Page or use Homebrew to install it:
$ brew install duaraghav8/tap/dockershrink
[!IMPORTANT] On MacOS, you will have to use homebrew because the compiled binary is not Notarized.
Usage
Navigate into the root directory of your Node.js project and invoke dockershrink:
# To optimize existing Docker-related files
$ dockershrink optimize
# To generate new Docker files
$ export DOCKERSHRINK_API_KEY=...
$ dockershrink generate
Dockershrink creates a new directory which contains the files produced by it.
By default, this directory is dockershrink.out.
For detailed information about a command, run
$ dockershrink help optimize
$ dockershrink help generate
You can also use the --debug option to get DEBUG logs. These are especially helpful during troubleshooting.
$ dockershrink generate --debug
Using AI Features
[!NOTE] Using AI features is optional for "optimize" (but highly recommended) and mandatory for "generate".
Dockershrink can use any OpenAI-compatible API endpoint for its AI features. This includes OpenAI, Anthropic, and AWS Bedrock.
If you want to enable AI, you must supply your API key and (optionally) a custom base URL for your chosen endpoint.
Requests will be sent to OpenAI's API by default, if no base URL is provided.
So even though Dockershrink itself is free, LLM usage might incur some cost for you.
dockershrink optimize --api-key <your endpoint's api key> --base-url <your endpoint's base url>
Or set them as environment variables:
export DOCKERSHRINK_API_KEY="<your endpoints api key>"
export DOCKERSHRINK_BASE_URL="<your endpoints base url>"
dockershrink generate
Examples:
-
OpenAI (default):
export DOCKERSHRINK_API_KEY="<your OpenAI API key>" dockershrink generate -
AWS Bedrock:
export DOCKERSHRINK_API_KEY="<your bedrock key>" export DOCKERSHRINK_BASE_URL="http://your-bedrock-endpoint" dockershrink generate -
Ollama:
# Assumes you are running a model that [supports tool calling](https://ollama.com/blog/tool-support) locally with Ollama dockershrink optimize --api-key 'ollama' --model "llama3.1"
[!NOTE] Dockershrink does not store your provided API Key.
So you must provide your key every time you want Dockershrink to use it. This is to avoid any unexpected costs.
Development :computer:
[!NOTE] This section is for authors and contributors. If you're simply interested in using Dockershrink, you can skip it.
Prerequisites
- Clone this repository on to your local machine.
- Make sure Golang is installed on your system (at least version 1.23)
- Make sure Docker installed on your system and the Docker daemon is running.
- Install GoReleaser (at least version 2.4)
Development
- After cloning this repository, navigate inside the root directory of the project
- Run tests to ensure everything is working
go test ./...
- Make your code changes, add relevant tests.
- Tidy up and make sure all tests pass
go mod tidy
go mod vendor
go test ./...
Build for local testing
# Single binary
goreleaser build --single-target --clean --snapshot
# All binaries
goreleaser release --snapshot --clean
Create a new release
- Create a Git Tag with the new version
git tag -a v0.1.0 -m "Release version 0.1.0"
git push origin v0.1.0
- Release
# Make sure GPG is present on your system and you have a default key which is added to Github.
# set your github access token
export GITHUB_TOKEN="<your GH token>"
goreleaser release --clean
This will create a new release under Releases and also make it available via Homebrew.