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 🧠
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 🚀
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.
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 🤯
Dockershrink aims to automatically apply advanced optimization techniques so engineers don't have to waste time on it and the organization still saves 💰!
You're welcome 😉
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.
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 OPENAI_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
Note
Using AI features is optional for "optimize" (but highly recommended) and mandatory for "generate".
If you want to enable AI, you must supply your OpenAI API Key.
So even though Dockershrink itself is free, openai usage might incur some cost for you.
dockershrink optimize --openai-api-key <your openai api key>
# Alternatively, you can supply the key as an environment variable
export OPENAI_API_KEY=<your openai api key>
dockershrink generate
Note
Dockershrink does not store your OpenAI API Key.
So you must provide your key every time you want Dockershrink to use it. This is to avoid any unexpected costs.
Note
This section is for authors and contributors. If you're simply interested in using Dockershrink, you can skip it.
- 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)
- 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 ./...
# Single binary
goreleaser build --single-target --clean --snapshot
# All binaries
goreleaser release --snapshot --clean
- 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.