$ recombobulate _
home / tips / ask-claude-to-audit-your-dockerfile-for-size-and-security
0

Ask Claude to Audit Your Dockerfile for Size and Security

bagwaa @bagwaa · Mar 26, 2026 · Performance
ask-claude-to-audit-your-dockerfile-for-size-and-security

A 1.2GB Docker image often only needs to be 120MB. Paste your Dockerfile and ask Claude to find what's bloating it.

Review this Dockerfile and identify specific changes to reduce the final image size
and improve security. Consider: multi-stage builds, layer caching order, removing
dev dependencies, Alpine vs slim base images, and any unnecessary packages.

Claude will spot the common culprits — COPY . . before installing dependencies (which busts the cache on every code change), apt-get without --no-install-recommends and cleanup, running as root, and choosing node:18 when node:18-alpine would shave 700MB.

Then ask for the rewrite:

Rewrite this Dockerfile using a multi-stage build. Stage 1 compiles assets and
installs all dependencies. Stage 2 is an Alpine-based runtime image that copies
only the production artifacts and runs as a non-root user.

For security, ask Claude to scan for hardcoded secrets, check that the final image doesn't include .git directories, and verify that sensitive build args aren't baked into layers.

The time investment is one prompt. The payoff is faster CI, smaller registries, and a smaller attack surface in production.

Your Dockerfile is probably 10 lines of good intentions and 5 lines of accidental bloat — Claude finds them instantly.

~/recombobulate $ tip --comments --count=0

Log in to leave a comment.

~/recombobulate $ tip --related --limit=3
0
Filter Test Output with a PreToolUse Hook to Cut Token Costs

A PreToolUse hook can intercept test runner commands and filter output to show only failures, cutting thousands of tokens from Claude's context.

bagwaa @bagwaa · 3 hours ago
0
Move Specialised CLAUDE.md Instructions into Skills to Shrink Context

CLAUDE.md loads into every message. Move workflow-specific instructions into skills that load on demand to reduce token costs across your session.

bagwaa @bagwaa · 3 hours ago
0
Use prompt.id to Trace All Activity from a Single User Prompt

Every event emitted while processing a single prompt shares a prompt.id UUID, letting you trace the complete chain of API calls and tool executions.

bagwaa @bagwaa · 3 hours ago