소스 정보
- 저장소
- tools-only/X-Skills
- 최근 소스 활동
- 2026년 2월 9일 04:32
- 감지된 SKILL.md 언어
- 영어
- 스타
- 7
- 포크
- 1
설치 방법
기본적으로 소스를 먼저 확인하는 Prompt가 선택됩니다. 직접 명령으로 전환하거나 로컬 사본을 다운로드할 수도 있습니다.
소스 파일 검토
설치 여부를 결정하기 전에 SKILL.md와 SkillsMP에 표시된 보조 파일을 읽어 보세요.
메뉴
기본적으로 소스를 먼저 확인하는 Prompt가 선택됩니다. 직접 명령으로 전환하거나 로컬 사본을 다운로드할 수도 있습니다.
설치 여부를 결정하기 전에 SKILL.md와 SkillsMP에 표시된 보조 파일을 읽어 보세요.
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
직접 명령은 검토 Prompt를 거치지 않습니다. 실행하기 전에 소스를 확인하세요.
npx skills add https://github.com/tools-only/X-Skills --skill docker-optimize명령은 한 줄로 유지됩니다. 복사하기 전에 가로로 스크롤해 전체 내용을 확인하세요.
로컬 사본을 원하시나요? SkillsMP에서 현재 제공할 수 있는 파일을 다운로드하세요.
SKILL.md 표시 중
| name | docker-optimize |
| description | Analyze and optimize Docker images for size and build speed |
| shortcut | do |
| category | devops |
| difficulty | advanced |
| estimated_time | 3 minutes |
Analyzes existing Docker images and Dockerfiles, identifying size/speed bottlenecks and providing specific optimizations with before/after metrics.
You are a Docker optimization expert. When user runs /docker-optimize or /do:
Analyze current state:
# Read existing Dockerfile
# Check image layers with: docker history <image>
# Calculate current size with: docker images <image>
Identify issues:
Calculate potential savings:
Current Image Size: 1,200 MB
Optimized Size: 150 MB
Reduction: 87% (1,050 MB saved)
Current Build Time: 5 min
Optimized Time: 1 min
Speedup: 80% faster
Provide optimized Dockerfile:
Show side-by-side comparison:
## Current State Analysis
**Image:** [image-name:tag]
**Base Image:** [current-base]
**Total Size:** [X MB]
**Build Time:** [Y min]
**Layers:** [N layers]
## Issues Identified
1. **[Issue]** - Impact: [size/time impact]
2. **[Issue]** - Impact: [size/time impact]
3. **[Issue]** - Impact: [size/time impact]
## Optimization Plan
**Target:**
- Size: [X MB] (↓ [Y]% reduction)
- Build Time: [X min] (↓ [Y]% faster)
- Layers: [N layers] (optimized)
# Optimized Dockerfile
[Complete optimized version with inline comments]
# Updated .dockerignore
[Additions to reduce build context]
## Before vs After
| Metric | Before | After | Improvement |
|--------------|-----------|-----------|-------------|
| Image Size | [X MB] | [Y MB] | ↓ [Z]% |
| Build Time | [X min] | [Y min] | ↓ [Z]% |
| Layers | [N] | [M] | Optimized |
| Base Image | [old] | [new] | Smaller |
| Security | root ️ | non-root | Hardened |
## Key Optimizations
1. **[Optimization]** - Saves [X MB / Y sec]
2. **[Optimization]** - Saves [X MB / Y sec]
3. **[Optimization]** - Saves [X MB / Y sec]
User: /do (with existing Dockerfile)
Current Dockerfile:
FROM node:20
WORKDIR /app
COPY . .
RUN npm install
EXPOSE 3000
CMD ["node", "index.js"]
Analysis:
## Current State Analysis
**Image:** my-app:latest
**Base Image:** node:20 (full Debian-based, ~900MB)
**Total Size:** 1,200 MB
**Build Time:** 3 min
**Layers:** 6 layers
## Issues Identified
1. **Bloated base image (node:20)** - Impact: +900MB
- Using full Debian when Alpine works
- Includes unnecessary build tools
2. **No multi-stage build** - Impact: +200MB
- Dev dependencies in production image
- npm cache included in final image
3. **Poor layer caching** - Impact: +2 min on code changes
- Copying all files before npm install
- Cache invalidated on any file change
4. **Missing .dockerignore** - Impact: +30 sec build time
- Copying node_modules, .git into build context
- Large unnecessary files slow down build
5. **Running as root** - Impact: Security vulnerability
- No non-root user configured
6. **No health check** - Impact: Production readiness
- Can't verify container health
## Optimization Plan
**Target:**
- Size: 150 MB (↓ 87% reduction, saves 1,050 MB)
- Build Time: 45 sec (↓ 75% faster, saves 2 min 15 sec)
- Layers: 8 layers (optimized for caching)
Optimized Dockerfile:
# Multi-stage build for Node.js
# Before: 1,200 MB | After: 150 MB (87% reduction)
# Stage 1: Build environment
FROM node:20-alpine AS builder
WORKDIR /app
# Copy package files FIRST (better caching)
# Changed: This layer only rebuilds when dependencies change
COPY package*.json ./
# Install ALL dependencies (dev + production)
RUN npm ci
# Copy source code AFTER installing deps
COPY . .
# Build step (if TypeScript/webpack/etc)
# RUN npm run build
# Stage 2: Production environment
FROM node:20-alpine AS production
# Create non-root user (security hardening)
RUN addgroup -g 1001 -S nodejs && \
adduser -S nodejs -u 1001
WORKDIR /app
# Copy package files
COPY package*.json ./
# Install ONLY production dependencies
# Changed: Excludes dev deps (jest, eslint, etc)
RUN npm ci --only=production && \
npm cache clean --force
# Copy built artifacts from builder stage
COPY --from=builder --chown=nodejs:nodejs /app .
# Switch to non-root user
USER nodejs
# Expose port
EXPOSE 3000
# Add health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD node -e "require('http').get('http://localhost:3000/health', (r) => {process.exit(r.statusCode === 200 ? 0 : 1)})"
# Start application
CMD ["node", "index.js"]
Updated .dockerignore:
# Prevent unnecessary files in build context
node_modules
npm-debug.log
.git
.gitignore
.env
.env.local
README.md
.vscode
.idea
.DS_Store
dist
build
coverage
.nyc_output
*.md
Before vs After:
| Metric | Before | After | Improvement |
|---|---|---|---|
| Image Size | 1,200 MB | 150 MB | ↓ 87% (-1,050 MB) |
| Build Time | 3 min | 45 sec | ↓ 75% (-2m 15s) |
| Layers | 6 | 8 | Optimized caching |
| Base Image | node:20 (900MB) | node:20-alpine (40MB) | -860 MB |
| Security | root ️ | nodejs user | Hardened |
| Health Check | None ️ | Configured | Production-ready |
Key Optimizations:
Multi-stage build - Saves 200MB
Alpine base image - Saves 860MB
Improved layer caching - Saves 2 min on rebuilds
.dockerignore - Saves 30 sec
npm cache clean - Saves 50MB
Non-root user - Security hardening
User: /do
Current Dockerfile:
FROM python:3.11
WORKDIR /app
COPY . .
RUN pip install -r requirements.txt
CMD ["python", "app.py"]
Analysis:
## Current State Analysis
**Image:** flask-app:latest
**Base Image:** python:3.11 (full Debian-based, ~900MB)
**Total Size:** 950 MB
**Build Time:** 2 min
**Layers:** 5 layers
## Issues Identified
1. **Bloated base image** - Impact: +900MB
2. **No .dockerignore** - Impact: +20 sec
3. **Poor layer caching** - Impact: +1 min
4. **Running as root** - Impact: Security risk
5. **Pip cache in image** - Impact: +50MB
## Optimization Plan
**Target:**
- Size: 120 MB (↓ 87%, saves 830 MB)
- Build Time: 40 sec (↓ 67%, saves 1 min 20 sec)
Optimized Dockerfile:
# Optimized Python Flask Dockerfile
# Before: 950 MB | After: 120 MB (87% reduction)
FROM python:3.11-slim AS production
# Prevent Python from buffering stdout/stderr
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1
# Create non-root user
RUN groupadd -g 1001 appuser && \
useradd -r -u 1001 -g appuser appuser
WORKDIR /app
# Copy requirements FIRST (better caching)
COPY requirements.txt .
# Install dependencies with no cache
RUN pip install --no-cache-dir -r requirements.txt
# Copy application code
COPY --chown=appuser:appuser . .
# Switch to non-root user
USER appuser
# Expose port
EXPOSE 8000
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \
CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8000/health').read()"
# Start application
CMD ["python", "app.py"]
Before vs After:
| Metric | Before | After | Improvement |
|---|---|---|---|
| Image Size | 950 MB | 120 MB | ↓ 87% (-830 MB) |
| Build Time | 2 min | 40 sec | ↓ 67% (-1m 20s) |
| Base Image | python:3.11 (900MB) | python:3.11-slim (130MB) | -770 MB |
Multi-stage builds typically save 80-90% size
Alpine/slim base images reduce size dramatically
Proper layer ordering speeds up rebuilds 5-10x
Always use .dockerignore (excludes unnecessary files)
Use --no-cache-dir with pip/npm to reduce size
After optimization, verify improvements:
# Build optimized image
docker build -t app:optimized .
# Compare sizes
docker images app:latest app:optimized
# Inspect layers
docker history app:optimized
# Measure build time
time docker build --no-cache -t app:optimized .
# Scan for vulnerabilities
docker scan app:optimized
# OR
trivy image app:optimized
# Test container
docker run -p 3000:3000 app:optimized
Issue: Alpine image causes errors → Some apps need glibc (alpine uses musl libc) → Try -slim variant instead (e.g., python:3.11-slim)
Issue: Build time didn't improve → Verify layer caching is working → Check if dependencies change frequently → Use BuildKit for advanced caching
Issue: Image still large after optimization
→ Use docker history <image> to find large layers
→ Check for large static files (move to CDN/volumes)
→ Verify .dockerignore is comprehensive
SOC 직업 분류 기준