# Docker Image Optimization

> Strategies for reducing builder image size and securing production containers.

- Skill: `creanlab/docker-image-optimization` (Agent Skill, multi-file: 4 files)
- Install (CLI): `npx skillmds@latest add creanlab/docker-image-optimization`
- Raw SKILL.md: https://api.skillmd.com/api/skills/creanlab/docker-image-optimization/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: DevOps & Infra
- Author: creanlab (https://skillmd.com/u/creanlab)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/creanlab/docker-image-optimization

---

# Docker Image Optimization

Strategies for reducing builder image size and securing production containers.

## When to use
- When operating in the `devops` domain.
- When resolving incidents related to docker image optimization.

## When not to use
- If the issue requires manual human intervention.
- If the domain does not apply.

## Triggers
- Pattern: `docker-image-optimization`
- Keywords: devops, docker

## Inputs
- Context from the current user session or incident report.

## Steps
### 1. Step 1
Analyze the current Dockerfile for multi-stage build support.

### 2. Step 2
Move compilation and heavy dependencies to the builder stage.

### 3. Step 3
Use a distroless or alpine base image for the final runtime stage.

### 4. Step 4
Clear package manager caches (e.g., `apt-get clean` or `rm -rf /var/cache/apk/*`) in the same layer they are installed.

## Success signals
- The task is resolved without regressions.
- Logs confirm the procedure was successfully applied.

## Failure modes
- Incorrect application of the steps leading to side effects.

## Safety notes
- Always verify changes in a staging environment before applying to production.
- Do not execute destructive commands without explicit authorization.

