Slim — Optimize Docker Containers with Automatic Minification
Slim (formerly DockerSlim) automatically analyzes and optimizes container images, shrinking them up to 30x by removing unnecessary files, packages, and layers.
What it is
Slim (formerly DockerSlim) automatically analyzes and optimizes Docker container images. It instruments your container, observes which files and libraries are actually used at runtime, then builds a minified image containing only those files. The result is an image that is up to 30x smaller with a reduced attack surface.
The tool targets DevOps engineers, security teams, and developers who want smaller, faster, and more secure container images without manually writing multi-stage Dockerfiles.
How it saves time or tokens
Manually optimizing Docker images requires identifying unused packages, writing multi-stage builds, and testing that nothing breaks. Slim automates this entire process: run one command and get an optimized image. No Dockerfile changes needed. The smaller images also reduce registry storage costs and container pull times.
How to use
- Install Slim:
brew install slimor download from GitHub releases. - Run Slim against your image:
slim build my-app:latest. - Use the optimized image:
my-app.slim:latest.
Example
# Install Slim
brew install slim
# Optimize a Node.js application image
slim build node-api:latest
# Compare sizes
docker images | grep node-api
# node-api latest 890MB
# node-api.slim latest 35MB
# Run the optimized image
docker run -p 3000:3000 node-api.slim:latest
# Advanced: keep specific paths and expose HTTP probes
slim build my-app:latest \
--include-path /app/config \
--http-probe-cmd /health
Related on TokRepo
- AI Tools for DevOps -- container and infrastructure optimization tools
- MCP Docker Integration -- Docker management for AI agents
Common pitfalls
- Slim removes files not accessed during its probe phase. If your app has code paths not triggered during probing (e.g., error handlers, cron jobs), those files may be removed. Use
--include-pathto keep them. - The probe phase runs your container. Ensure the container can start and respond to health checks in the Slim environment.
- Slim works best with server applications that have clear startup and request handling. Batch jobs or CLI tools may need custom probe commands.
Frequently Asked Questions
Slim instruments the container with syscall tracing during a probe phase. It runs the container, sends HTTP probes, and records every file accessed. Files not accessed are excluded from the optimized image.
No. Slim operates on built images, not Dockerfiles. It takes your existing image as input and produces an optimized copy. Your Dockerfile and build process remain unchanged.
Typical reductions are 5-30x depending on the base image and application. A 900MB Node.js image might shrink to 30-50MB. Alpine-based images see smaller reductions since they are already minimal.
Yes, with proper testing. Run your test suite against the optimized image before deploying. The main risk is missing files for code paths not exercised during the probe phase.
Slim works on Linux amd64 and arm64 images. It does not currently support Windows containers. Multi-platform manifest support depends on the version.
Citations (3)
- Slim GitHub— Automatically optimize Docker images up to 30x smaller
- Slim Official Site— Runtime analysis with syscall tracing
- Slim README— Formerly known as DockerSlim
Related on TokRepo
Discussion
Related Assets
MessagePack — Efficient Binary Serialization Format for Cross-Language Data Exchange
MessagePack is a compact binary serialization format that is faster and smaller than JSON. With libraries available for 50+ programming languages, it provides a schema-less drop-in alternative for any JSON-based data exchange.
Apache Thrift — Cross-Language RPC and Serialization Framework
Apache Thrift is a software framework for building scalable cross-language services. It combines a code generation engine with an interface definition language to create efficient RPC clients and servers in C++, Java, Python, Go, and 20+ other languages.
Seaborn — Statistical Data Visualization Built on Matplotlib
Seaborn is a Python data visualization library built on top of Matplotlib that provides a high-level interface for drawing attractive and informative statistical graphics with minimal code.