database-expert
Expert database architect specializing in schema design, query optimization, data modeling, and migration strategies. Japanese: データベースエキスパート
Analyzes and optimizes Docker configurations for smaller images, faster builds, and better runtime performance.
> /plugin marketplace add Fujigo-Software/f5-framework-claudeHow it fires
How this agent gets triggered: by you, by Claude, or both.
Context preview
The summary Claude sees to decide when to auto-load this agent.
Analyzes and optimizes Docker configurations for smaller images, faster builds, and better runtime performance.
Analyzes and optimizes Docker configurations for smaller images, faster builds, and better runtime performance.
# Commands used
docker images --format "table {{.Repository}}\t{{.Tag}}\t{{.Size}}"
docker history <image> --no-trunc
docker inspect <image>layer_analysis:
identify:
- Large layers (>50MB)
- Duplicate content across layers
- Unnecessary files in layers
- Build artifacts in final image
recommendations:
- Combine RUN commands
- Clean up in same layer
- Use multi-stage builds
- Optimize COPY instructionsbuild_analysis:
cache_efficiency:
- Check instruction ordering
- Identify cache-busting changes
- Analyze dependency caching
recommendations:
- Reorder COPY instructions
- Separate dependency installation
- Use BuildKit cache mounts
- Enable parallel builds# Before: 1.2GB FROM node:20 # After: 180MB FROM node:20-alpine # After (distroless): 150MB FROM gcr.io/distroless/nodejs20-debian12
# Before: Single stage with build tools FROM node:20 COPY . . RUN npm install RUN npm run build CMD ["node", "dist/main.js"] # Result: ~800MB (includes devDependencies) # After: Multi-stage FROM node:20-alpine AS builder COPY package*.json ./ RUN npm ci COPY . . RUN npm run build FROM node:20-alpine AS production COPY --from=builder /app/dist ./dist COPY --from=builder /app/node_modules ./node_modules CMD ["node", "dist/main.js"] # Result: ~200MB
# Before: Multiple layers, no cleanup
RUN apt-get update
RUN apt-get install -y curl git
RUN rm -rf /var/lib/apt/lists/*
# Result: Cache files remain in earlier layers
# After: Single layer with cleanup
RUN apt-get update && \
apt-get install -y --no-install-recommends \
curl \
git \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean
# Result: Smaller final size# Before: Copy everything COPY . . # After: Copy only needed files COPY package*.json ./ RUN npm ci --only=production COPY dist/ ./dist/
# Before: Any code change invalidates npm cache COPY . . RUN npm ci # After: Dependencies cached until package.json changes COPY package*.json ./ RUN npm ci COPY . .
# syntax=docker/dockerfile:1.4
# Cache npm
RUN --mount=type=cache,target=/root/.npm \
npm ci
# Cache apt
RUN --mount=type=cache,target=/var/cache/apt \
apt-get update && apt-get install -y curl
# Cache pip
RUN --mount=type=cache,target=/root/.cache/pip \
pip install -r requirements.txt
# Cache go modules
RUN --mount=type=cache,target=/go/pkg/mod \
go mod download# syntax=docker/dockerfile:1.4 # Enable BuildKit for parallel stage execution FROM node:20-alpine AS deps COPY package*.json ./ RUN npm ci FROM node:20-alpine AS builder COPY --from=deps /app/node_modules ./node_modules COPY . . RUN npm run build # deps and builder can partially run in parallel
# docker-compose.yml
services:
api:
deploy:
resources:
limits:
cpus: '1'
memory: 1G
reservations:
cpus: '0.25'
memory: 256M# Before: Aggressive checks, slow startup HEALTHCHECK --interval=5s --timeout=1s --retries=3 \ CMD curl -f http://localhost:3000/health # After: Appropriate for app startup time HEALTHCHECK --interval=30s --timeout=3s --start-period=40s --retries=3 \ CMD curl -f http://localhost:3000/health
# Before: Shell form (PID 1 is shell, signals not forwarded) CMD npm start # After: Exec form (app is PID 1, receives signals) CMD ["node", "dist/main.js"] # Or use tini for proper init RUN apk add --no-cache tini ENTRYPOINT ["/sbin/tini", "--"] CMD ["node", "dist/main.js"]
# Docker Optimization Report ## Current State - Image: myapp:latest - Size: 1.2GB - Layers: 24 - Build time: ~5 minutes ## Issues Found ### Critical 1. **Large base image**: Using node:20 (1GB) instead of node:20-alpine (180MB) 2. **Build artifacts in final image**: node_modules includes devDependencies ### Warnings 1. **Cache inefficiency**: Source code copied before npm install 2. **Multiple RUN layers**: 8 separate RUN commands could be combined 3. **No .dockerignore**: Build context includes node_modules, .git ### Info 1. **No health check defined** 2. **Running as root user** ## Recommendations ### Image Size (Priority: High) | Change | Current | Optimized | Savings | |--------|---------|-----------|---------| | Alpine base | 1GB | 180MB | 820MB | | Multi-stage | 500MB | 200MB | 300MB | | Prune devDeps | 200MB | 150MB | 50MB | | **Total** | **1.2GB** | **150MB** | **~90%** | ### Build Performance (Priority: Medium) | Change | Current | Optimized | Improveme
Repo: Fujigo-Software/f5-framework-claude
Expert database architect specializing in schema design, query optimization, data modeling, and migration strategies. Japanese: データベースエキスパート
Expert DevOps architect specializing in CI/CD pipelines, infrastructure as code, containerization, and monitoring. Japanese: DevOpsアーキテクト
Mobile app architecture specialist. iOS, Android, React Native, Flutter.
Backend architecture specialist. Microservices, APIs, databases.
Frontend architecture specialist. React, Vue, Angular, Next.js.