optimize-image

A Dockerfile review command that examines how a container image is built. A container image is a packaged application with the files and software it needs to run.

In plain words
What is it for?
Use it to review a Dockerfile and get recommendations about base images, build stages, dependency layers, caching, unused packages, secrets, and non-root users.
Why use it?
It helps identify ways to reduce image size and build time while improving basic image security. It points out issues such as missing multi-stage builds, poor layer ordering, or running as root.

Command

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add commands/armanzeroeight/fastagent-plugins/optimize-image
Clone the repo
git clone --depth 1 https://github.com/armanzeroeight/fastagent-plugins
Per session 14 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 1,058 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00014 $0.01058
Opus 5 $0.00007 $0.00529
Sonnet 5 $0.00003 $0.00212
Haiku 4.5 $0.00001 $0.00106

Measured yesterday against content hash b631e5d894a4, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

optimize-image scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

plugins/docker-toolkit/commands/optimize-image.md · 181 lines

How it starts

The opening of the file, as written. The whole thing — 181 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Optimize Image

Context

  • Dockerfile location: !find . -name "Dockerfile" -o -name "dockerfile" | head -5
  • Current images: !docker images --format "table {{.Repository}}\t{{.Tag}}\t{{.Size}}" | head -10
  • Docker version: !docker --version

Your Task

Analyze the Dockerfile and provide comprehensive optimization recommendations.

Arguments

  • $1 (optional): Path to Dockerfile (default: ./Dockerfile)

Steps

  1. Read and analyze Dockerfile:

    cat Dockerfile
    
  2. Identify optimization opportunities:

    Base Image:

    • Is alpine or slim variant used?
    • Is specific tag used (not latest)?
    • Can distroless be used?

    Multi-Stage Build:

    • Is multi-stage build used?
    • Are build dependencies separated from runtime?
    • Can final image be smaller?

    Layer Optimization:

    • Are dependencies copied before code?
    • Are RUN commands combined appropriately?
    • Is .dockerignore present?

    Security:

    • Is non-root user used?
    • Are secrets avoided in image?
    • Are unnecessary packages removed?

    Caching:

    • Are layers ordered by change frequency?
    • Are package manager caches cleared?
    • Can build cache mounts be used?
  3. Calculate current image size:

    docker build -t temp-analysis .
    docker images temp-analysis --format "{{.Size}}"
    docker rmi temp-analysis
    
  4. Generate optimized Dockerfile:

    Create Dockerfile.optimized with improvements:

    • Minimal base image
    • Multi-stage build (if applicable)
    • Optimized layer order
    • Security hardening
    • Cache optimization
  5. Provide comparison:

    Before:

    • Image size: X MB
    • Layers: Y
    • Security issues: Z

    After (estimated):

    • Image size: A MB (B% reduction)
    • Layers: C
    • Security improvements: D
  6. Create optimization report:

    # Dockerfile Optimization Report
    
    ## Current Analysis
    - Base image: node:18 (990MB)
    - Build type: Single-stage
    - Security: Running as root
    - Layers: 12
    
    ## Recommendations
    
    ### High Priority
    1. Use alpine base (node:18-alpine)
       - Savings: ~800MB
       - Impact: High
    
    2. Implement multi-stage build
       - Savings: ~200MB
       - Impact: High
    
    3. Run as non-root user
       - Security: Critical
       - Impact: High
    
    ### Medium Priority
    4. Optimize layer caching
       - Build time: -50%
       - Impact: Medium
    
    5. Add .dockerignore
       - Build time: -20%
       - Impact: Medium
    
    ### Low Priority
    6. Combine RUN commands
       - Savings: ~10MB
       - Impact: Low
    
    ## Implementation
    
    See Dockerfile.optimized for complete implementation.
    
    ## Next Steps
    1. Review Dockerfile.optimized
    2. Test build: `docker build -f Dockerfile.optimized -t myapp:optimized .`
    3. Compare sizes: `docker images myapp`
    4. Test functionality
    5. Replace Dockerfile when satisfied
    

Read the full file on GitHub · 181 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 181 lines · 14 tokens per session scan A b631e5d894a4

Subscribe to this mod's changes

optimize-image is a command published in the GitHub repository armanzeroeight/fastagent-plugins (29 stars, last pushed 1mo ago), licensed MIT. It adds 14 tokens to every session and 1,058 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.