npx skills add ...
npx skills add rknall/claude-skills --skill docker-configuration-validator
Comprehensive Docker and Docker Compose validation following best practices and security standards. Use this skill when users ask to validate Dockerfiles, review Docker configurations, check Docker Compose files, verify multi-stage builds, audit Docker security, or ensure compliance with Docker best practices. Validates syntax, security, multi-stage builds, and modern Docker Compose requirements.
npx skills add rknall/claude-skills --skill docker-configuration-validator
This skill provides comprehensive validation for Dockerfiles and Docker Compose files, ensuring compliance with best practices, security standards, and modern syntax requirements.
Activate this skill when the user requests:
When a user requests Docker validation, start by understanding the scope:
Identify What to Validate
Understand Requirements
Check Available Tools
Find all Dockerfiles in the project:
If Hadolint is available:
If Hadolint is NOT available:
Check each Dockerfile for critical issues:
1. Base Image Best Practices
:latest tags2. Multi-Stage Build Verification
Analysis:
3. Security Checks
4. Layer Optimization
5. Best Practices
Classify findings by severity:
CRITICAL (Must Fix):
:latest tagsHIGH (Should Fix):
MEDIUM (Recommended):
LOW (Nice to Have):
Find all Docker Compose files:
CRITICAL CHECK: Modern Docker Compose (v2.27.0+) does NOT use version field
Old (Deprecated):
New (Modern):
1. Image Best Practices
:latest tags2. Service Configuration
3. Networking
4. Volumes & Persistence
5. Environment & Secrets
6. Security
When validating multi-stage builds, ensure:
1. Stage Structure
2. Validation Checklist
3. Common Patterns to Check
Node.js Multi-Stage:
Python Multi-Stage:
Go Multi-Stage:
Perform comprehensive security checks:
1. User & Permissions
2. Exposed Secrets
3. Vulnerable Base Images
4. Network Exposure
Structure the validation report:
[Provide custom validation script based on project needs]
[Provide GitHub Actions / GitLab CI configuration]
When conducting validation:
Be Thorough
Prioritize Clearly
Provide Specific Fixes
Educate
Be Actionable
:latest tags (DL3006):latest tagsWhen providing recommendations, reference:
Remember: Docker validation is about ensuring reliable, secure, and efficient containerized applications. Always prioritize security and production readiness while maintaining developer experience.
# Count FROM statements (should be >= 2 for multi-stage)
FROM_COUNT=$(grep -c "^FROM " Dockerfile)
# Check for named stages
NAMED_STAGES=$(grep -c "^FROM .* AS " Dockerfile)
# Check for inter-stage copies
COPY_FROM=$(grep -c "COPY --from=" Dockerfile)find . -maxdepth 3 -type f \( -name "docker-compose*.yml" -o -name "docker-compose*.yaml" -o -name "compose*.yml" \)# Check for obsolete version field
if grep -q "^version:" docker-compose.yml; then
echo "❌ ERROR: Found obsolete 'version' field"
echo "Remove 'version:' line - it's obsolete in Compose v2.27.0+"
fiversion: '3.8' # ❌ REMOVE THIS
services:
web:
image: nginx:latest# No version field!
services:
web:
image: nginx:1.24-alpine# Syntax validation
docker compose config --quiet
# Show resolved configuration
docker compose config
# Validate specific file
docker compose -f docker-compose.prod.yml config --quiet# Lint compose file
dclint docker-compose.yml
# Auto-fix issues
dclint --fix docker-compose.yml
# JSON output
dclint --format json docker-compose.yml# Build stage
FROM node:20-bullseye AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build && npm run test
# Production stage
FROM node:20-alpine AS runtime
WORKDIR /app
COPY --from=builder /app/dist ./dist
USER node
CMD ["node", "dist/index.js"]# Check for USER directive
USER_COUNT=$(grep -c "^USER " Dockerfile)
LAST_USER=$(grep "^USER " Dockerfile | tail -1 | awk '{print $2}')
if [ "$USER_COUNT" -eq 0 ]; then
echo "❌ CRITICAL: No USER specified (runs as root!)"
elif [ "$LAST_USER" == "root" ] || [ "$LAST_USER" == "0" ]; then
echo "❌ CRITICAL: Final USER is root"
finame: Docker Validation
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main ]
jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Lint Dockerfiles
uses: hadolint/hadolint-action@v3.1.0
with:
dockerfile: ./Dockerfile
failure-threshold: error
- name: Validate Compose files
run: |
for f in $(find . -name "*compose*.yml"); do
docker compose -f "$f" config --quiet
done
- name: Check for obsolete version field
run: |
if grep -r "^version:" . --include="*compose*.yml"; then
echo "ERROR: Found obsolete version field"
exit 1
fistages:
- validate
docker-validation:
stage: validate
image: hadolint/hadolint:latest-debian
script:
- find . -name "Dockerfile*" -exec hadolint {} \;
- |
for f in $(find . -name "*compose*.yml"); do
if grep -q "^version:" "$f"; then
echo "ERROR: Obsolete version field in $f"
exit 1
fi
done