x402

Dockerfile Generate (x402)

Generate optimized, production-ready Dockerfiles. Multi-stage builds, Alpine base, non-root user, layer caching. Supports Node, Python, Go, Rust, Java.

get/x402/v2/dockerfile-generate

Request

  • Base URL: https://api.strale.io
  • URL: https://api.strale.io/x402/v2/dockerfile-generate
  • Auth: none required

Query parameters

alpineboolean
languagestring required
frameworkstring
multi_stageboolean

Response

Success

dockerfilestring
estimated_image_sizestring

Example response

{
  "stages": [
    "dependencies",
    "builder",
    "runtime"
  ],
  "language": "en",
  "framework": "express",
  "build_args": [],
  "dockerfile": "# Stage 1: Dependencies\nFROM node:18-alpine AS dependencies\nWORKDIR /app\nCOPY package*.json ./\nRUN npm ci --only=production && npm cache clean --force\n\n# Stage 2: Builder\nFROM node:18-alpine AS builder\nWORKDIR /app\nCOPY package*.json ./\nRUN npm ci\nCOPY . .\nRUN npm run build --if-present\n\n# Stage 3: Runtime\nFROM node:18-alpine AS runtime\nWORKDIR /app\n\n# Install dumb-init for proper signal handling\nRUN apk add --no-cache dumb-init\n\n# Create non-root user\nRUN addgroup -g 1001 -S nodejs && adduser -S nodejs -u 1001\n\n# Copy production dependencies from dependencies stage\nCOPY --from=dependencies --chown=nodejs:nodejs /app/node_modules ./node_modules\n\n# Copy application code from builder stage\nCOPY --from=builder --chown=nodejs:nodejs /app/package*.json ./\nCOPY --from=builder --chown=nodejs:nodejs /app/dist ./dist\nCOPY --from=builder --chown=nodejs:nodejs /app/public ./public\n\n# Switch to non-root user\nUSER nodejs\n\n# Expose port\nEXPOSE 3000\n\n# Healthcheck\nHEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \\\n  CMD node -e \"require('http').get('http://localhost:3000/health', (r) => {if (r.statusCode !== 200) throw new Error(r.statusCode)})\"\n\n# Use dumb-init to handle signals properly\nENTRYPOINT [\"dumb-init\", \"--\"]\n\n# Start application\nCMD [\"node\", \"dist/index.js\"]",
  "multi_stage": true,
  "security_notes": [
    "Non-root user (nodejs:1001) runs the application",
    "Multi-stage build reduces final image size by excluding dev dependencies",
    "Alpine Linux base image minimizes attack surface",
    "dumb-init handles PID 1 and signal forwarding correctly",
    "Only production dependencies copied to final stage",
    "Read-only filesystem recommended in production via security context",
    "No package manager or build tools in final image",
    "HEALTHCHECK validates application responsiveness"
  ],
  "estimated_image_size": "120-150MB",
  "dockerignore_recommended": [
    "node_modules",
    "npm-debug.log",
    ".git",
    ".gitignore",
    ".env",
    ".env.local",
    ".DS_Store",
    "dist",
    "build",
    ".next",
    "coverage",
    ".nyc_output",
    "*.log",
    ".vscode",
    ".idea",
    "*.swp",
    "*.swo",
    "*~",
    ".eslintcache",
    "yarn-error.log",
    ".npm",
    ".eslintignore",
    "README.md",
    "LICENSE",
    ".editorconfig",
    "docker-compose*.yml",
    "Dockerfile*",
    ".dockerignore",
    ".github",
    ".gitlab-ci.yml",
    ".circleci",
    "test",
    "tests",
    "jest.config.js",
    "vitest.config.js",
    ".mocharc.json"
  ]
}

Changes

No recorded changes to this operation across all 1 revision of this API.