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.
Installation avec revue préalable
Cet actif nécessite une revue. Le prompt copié demande un dry-run, affiche les écritures, puis continue seulement après confirmation.
npx -y tokrepo@latest install bebccaab-3986-11f1-9bc6-00163e2b0d79 --target codexDry-run d'abord, confirmez les écritures, puis lancez cette commande.
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.
Questions fréquentes
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.
Sources citées (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
En lien sur TokRepo
Fil de discussion
Actifs similaires
Dive — Explore Docker Image Layers and Optimize Size
Dive is a tool for exploring Docker image contents layer by layer. It shows exactly what changed in each layer, identifies wasted space, and helps you optimize your Dockerfiles for smaller, more efficient container images.
Docker Agent — Run Agent Tasks in Containers
Docker Agent packages agent workloads into containers so you get reproducible environments, clear boundaries, and safer runs than ad-hoc local scripts.
Arcane — Modern Self-Hosted Docker Management Platform
A sleek, modern Docker management UI for creating, monitoring, and managing containers, images, volumes, and networks with a clean web dashboard.
Docker (Moby) — The Container Platform That Changed DevOps
Docker is the platform that popularized containerization. It packages applications with their dependencies into standardized containers that run consistently everywhere. Moby is the open-source project behind Docker Engine, the runtime that powers container-based development and deployment.