$npx -y skills add mjunaidca/mjs-agent-skills --skill dockerProduction-grade Docker containerization for Python and Node.js applications. This skill should be used when users ask to containerize applications, create Dockerfiles, dockerize projects, or set up Docker Compose. Auto-detects project structure, analyzes .env for secrets, valida
| 1 | # Docker |
| 2 | |
| 3 | Production-grade Docker containerization with security-first defaults. |
| 4 | |
| 5 | --- |
| 6 | |
| 7 | ## Resource Detection & Adaptation |
| 8 | |
| 9 | **Before generating Dockerfiles/Compose, detect the environment:** |
| 10 | |
| 11 | ```bash |
| 12 | # Detect host machine memory |
| 13 | sysctl -n hw.memsize 2>/dev/null | awk '{print $0/1024/1024/1024 " GB"}' || \ |
| 14 | grep MemTotal /proc/meminfo | awk '{print $2/1024/1024 " GB"}' |
| 15 | |
| 16 | # Detect Docker allocated resources |
| 17 | docker info --format 'Memory: {{.MemTotal}}, CPUs: {{.NCPU}}' |
| 18 | |
| 19 | # Detect available disk space |
| 20 | docker system df |
| 21 | ``` |
| 22 | |
| 23 | **Adapt configurations based on detection:** |
| 24 | |
| 25 | | Detected Docker Memory | Profile | Build Memory | Container Limits | |
| 26 | |-----------------------|---------|--------------|------------------| |
| 27 | | < 4GB | Constrained | 1GB | 256Mi | |
| 28 | | 4-8GB | Minimal | 2GB | 512Mi | |
| 29 | | 8-12GB | Standard | 4GB | 1Gi | |
| 30 | | > 12GB | Extended | 8GB | 2Gi | |
| 31 | |
| 32 | ### Agent Behavior |
| 33 | |
| 34 | 1. **Detect** Docker resources before generating compose.yaml |
| 35 | 2. **Adapt** resource limits to available memory |
| 36 | 3. **Warn** if build may fail due to insufficient resources |
| 37 | 4. **Calculate** safe limits: `docker_memory * 0.6 / container_count` |
| 38 | |
| 39 | ### Adaptive Compose Templates |
| 40 | |
| 41 | **Constrained (< 4GB Docker):** |
| 42 | ```yaml |
| 43 | services: |
| 44 | app: |
| 45 | deploy: |
| 46 | resources: |
| 47 | limits: |
| 48 | memory: 256M |
| 49 | cpus: '0.25' |
| 50 | build: |
| 51 | args: |
| 52 | - BUILDKIT_STEP_LOG_MAX_SIZE=10000000 |
| 53 | ``` |
| 54 | ⚠️ Agent should warn: "Docker memory low. Multi-stage builds may fail." |
| 55 | |
| 56 | **Standard (4-8GB Docker):** |
| 57 | ```yaml |
| 58 | services: |
| 59 | app: |
| 60 | deploy: |
| 61 | resources: |
| 62 | limits: |
| 63 | memory: 512M |
| 64 | cpus: '0.5' |
| 65 | reservations: |
| 66 | memory: 256M |
| 67 | ``` |
| 68 | |
| 69 | **Extended (> 8GB Docker):** |
| 70 | ```yaml |
| 71 | services: |
| 72 | app: |
| 73 | deploy: |
| 74 | resources: |
| 75 | limits: |
| 76 | memory: 1G |
| 77 | cpus: '1.0' |
| 78 | reservations: |
| 79 | memory: 512M |
| 80 | ``` |
| 81 | |
| 82 | ### Pre-Build Validation |
| 83 | |
| 84 | Before running `docker build`, agent should verify: |
| 85 | ```bash |
| 86 | # Check available memory |
| 87 | docker info --format '{{.MemTotal}}' | awk '{if ($1 < 4000000000) print "WARNING: Low memory"}' |
| 88 | ``` |
| 89 | |
| 90 | If constrained: use `--memory` flag and warn user about potential build failures. |
| 91 | |
| 92 | --- |
| 93 | |
| 94 | ## What This Skill Does |
| 95 | |
| 96 | **Analysis & Detection:** |
| 97 | - Auto-detects runtime, framework, version, entrypoint (no questions) |
| 98 | - Scans .env files, classifies secrets vs build-args vs runtime config |
| 99 | - Detects native dependencies, generates correct build deps |
| 100 | - Identifies missing configs (Next.js standalone, health endpoints) |
| 101 | |
| 102 | **Generation:** |
| 103 | - Creates multi-stage Dockerfiles customized to YOUR project structure |
| 104 | - Generates compose.yaml with security defaults (non-root, read-only, resource limits) |
| 105 | - Adds health endpoints if missing |
| 106 | - Fixes configuration issues (adds `output: 'standalone'` to Next.js, etc.) |
| 107 | |
| 108 | **Validation:** |
| 109 | - Builds both dev and production targets before delivering |
| 110 | - Verifies health endpoints work |
| 111 | - Confirms non-root user in production |
| 112 | - Warns about any secrets that would leak into image |
| 113 | - Reports image size |
| 114 | |
| 115 | **Security:** |
| 116 | - Never bakes secrets into images |
| 117 | - Non-root user by default |
| 118 | - Minimal attack surface (multi-stage builds) |
| 119 | - Pinned versions (no `:latest`) |
| 120 | - Security scan command included |
| 121 | |
| 122 | ## What This Skill Does NOT Do |
| 123 | |
| 124 | - Generate Kubernetes manifests (use dedicated k8s skill) |
| 125 | - Create Helm charts (use dedicated helm skill) |
| 126 | - Handle Bun/Deno (use dedicated skills) |
| 127 | - Copy templates blindly without customization |
| 128 | |
| 129 | --- |
| 130 | |
| 131 | ## Before Implementation |
| 132 | |
| 133 | Gather context to ensure successful implementation: |
| 134 | |
| 135 | | Source | Gather | |
| 136 | |--------|--------| |
| 137 | | **Codebase** | Package files, existing Dockerfile, .env patterns | |
| 138 | | **Conversation** | Dev vs production target, base image preferences | |
| 139 | | **Skill References** | Framework patterns, multi-stage builds, security | |
| 140 | | **User Guidelines** | Registry conventions, naming standards | |
| 141 | |
| 142 | --- |
| 143 | |
| 144 | ## Required Clarifications |
| 145 | |
| 146 | Ask when not auto-detectable: |
| 147 | |
| 148 | | Question | When to Ask | |
| 149 | |----------|-------------| |
| 150 | | Target environment | "Building for development or production?" | |
| 151 | | Base image preference | "Standard slim images or enterprise hardened?" | |
| 152 | | Existing Docker files | "Enhance existing Dockerfile or create new?" | |
| 153 | | Registry target | "Local only or pushing to registry?" | |
| 154 | |
| 155 | --- |
| 156 | |
| 157 | ## Detect Runtime |
| 158 | |
| 159 | | File Present | Runtime | Package Manager | |
| 160 | |--------------|---------|-----------------| |
| 161 | | `requirements.txt`, `pyproject.toml`, `uv.lock` | Python | pip/uv | |
| 162 | | `pnpm-lock.yaml` | Node.js | pnpm | |
| 163 | | `yarn.lock` | Node.js | yarn | |
| 164 | | `package-lock.json` | Node.js | npm | |
| 165 | |
| 166 | - |