Skip to main content

Commandline tool to reduce the size of your Docker Images

Project description

DockerShrink

Dockershrink is an AI-powered Commandline Tool that helps you reduce the size of your Docker images.

Typical interaction with dockershrink CLI

It combines the power of traditional Rule-based 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.

[!IMPORTANT] Dockershrink is BETA software.

We would love to hear what you think! 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.

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 auomatically apply advanced optimization techniques so engineers don't have to waste time on it and the organization still reaps the benefits!

You're welcome :wink:

How it works

Currently, the CLI is the primary way to interact with dockershrink.

When you invoke it on your project, it analyzes code files.

Dockershrink looks for the following files:

:point_right: Dockerfile (Required)

:point_right: package.json (Optional)

:point_right: .dockerignore (Optional, created if doesn't already exist)

It then creates a new directory (default: dockershrink.optimized) inside the project, which contains modified versions of your files that will result in a smaller Docker Image.

The CLI outputs a list of actions it took over your files.

It may also include suggestions on further improvements you could make.

Installation

You can install dockershrink using PIP or PIPX

$ pip install dockershrink
$ pipx install dockershrink

If you're using MacOS or Linux, you can also use Homebrew to install dockershrink

brew install dockershrink

Usage

Navigate into the root directory of one of your Node.js projects and invoke dockershrink with the optimize command:

$ dockershrink optimize

Dockershrink will create a new directory with the optimized files and output the actions taken and (maybe) some more suggestions.

For detailed information about the optimize command, run

dockershrink optimize --help

Using AI Features

[!NOTE] Using AI features is optional, but highly recommended for more customized and powerful optimizations.

To use AI, you need to supply your own OpenAI API key, so even though Dockershrink itself is free, openai usage might incur some cost for you.

By default, dockershrink only runs rule-based analysis to optimize your image definition.

If you want to enable AI, you must supply your OpenAI API Key.

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 optimize

[!NOTE] Dockershrink does not store your OpenAI API Key.

So you must provide your key every time you want "optimize" to use AI features.

Default file paths

By default, the CLI looks for the files to optimize in the current directory.

You can also specify the paths to all files using options (see dockershrink optimize --help for the available options).

Development

[!NOTE] This section is for authors and contributors. If you're simply interested in using Dockershrink, you can skip this section.

  1. Clone this repository
  2. Navigate inside the root directory of the project and create a new virtual environment
python3 -m venv .venv
source .venv/bin/activate
  1. Install all dependencies
pip install --no-cache-dir -r requirements.txt
  1. Install the editable CLI tool
# -e ensures that the tool is editable, ie, code changes reflect in the tool immediately, without having to re-install it
pip install -e .

# Try running the cli
dockershrink --help
  1. Make your code changes
  2. Run black
black .
  1. In case of any changes in dependencies, update requirements.txt
pip freeze > requirements.txt

Release

Once all code changes have been made for the next release, upgrade the version in pyproject.toml and cli.py.

Then proceed to follow these steps to release new dockershrink version on PyPI:

  1. Build dockershrink from source
python -m build
  1. Upload to testpypi
twine upload --repository testpypi dist/*
  1. The new version of the package should now be available in TestPyPI.
  2. Try installing the test package
pip install --index-url https://test.pypi.org/simple/ --no-deps dockershrink
  1. Upload the package to PyPI
twine upload dist/*
  1. The new version of the package should now be available in PyPI

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dockershrink-0.1.2.tar.gz (44.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dockershrink-0.1.2-py3-none-any.whl (47.4 kB view details)

Uploaded Python 3

File details

Details for the file dockershrink-0.1.2.tar.gz.

File metadata

  • Download URL: dockershrink-0.1.2.tar.gz
  • Upload date:
  • Size: 44.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.0

File hashes

Hashes for dockershrink-0.1.2.tar.gz
Algorithm Hash digest
SHA256 00c3fd4174e6cf3de22c0280e2cec3c22a6333d456732706f6f69eca58915816
MD5 3d53d04af77f9921e6dcb6fbb5f1714f
BLAKE2b-256 be811615375c81a6d6a19908334e5c066a6c205a3a6c85b23edc5053328e250f

See more details on using hashes here.

File details

Details for the file dockershrink-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: dockershrink-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 47.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.0

File hashes

Hashes for dockershrink-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1449f89a4b5e6df891a4d45e291b178b025aed80d87d9f3f2ed104ca4fbfd6d3
MD5 019b8c59e08896b0302ac3cdca53ccf7
BLAKE2b-256 dfae1a717826ef1380a5f0f417a5bfc9f53ec2d0d3b7555ec9a0f4317ed1255d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page