ConfigsApr 16, 2026·3 min read

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.

TL;DR
Slim shrinks Docker images up to 30x by automatically removing unnecessary files and packages.
§01

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.

§02

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.

§03

How to use

  1. Install Slim: brew install slim or download from GitHub releases.
  2. Run Slim against your image: slim build my-app:latest.
  3. Use the optimized image: my-app.slim:latest.
§04

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
§05

Related on TokRepo

§06

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-path to 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

How does Slim know which files to keep?+

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.

Does Slim change my Dockerfile?+

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.

How much can Slim reduce image size?+

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.

Is the optimized image safe for production?+

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.

Does Slim support multi-platform images?+

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)

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets