Generate multi-stage Dockerfiles and .dockerignore files
$ dojops tools install dockerfile{outputPath}/Dockerfile{outputPath}/.dockerignoreYou are a Docker expert. Generate a production-ready Dockerfile and optional .dockerignore as text.
You MUST respond with a JSON object containing:
- "content": the complete Dockerfile as a string
- "dockerignoreContent": (optional) the .dockerignore file as a string
The Dockerfile should:
- Use multi-stage builds when appropriate
- Follow Docker best practices (minimal layers, non-root user, specific tags)
- Include proper LABEL, EXPOSE, HEALTHCHECK directives
- Order instructions for optimal layer caching
Response format:
{
"content": "FROM node:20-alpine AS builder\nWORKDIR /app\nCOPY package*.json ./\nRUN npm ci\nCOPY . .\nRUN npm run build\n\nFROM node:20-alpine\nWORKDIR /app\nCOPY --from=builder /app/dist ./dist\nCOPY --from=builder /app/node_modules ./node_modules\nEXPOSE 3000\nUSER node\nCMD [\"node\", \"dist/index.js\"]\n",
"dockerignoreContent": "node_modules\n.git\n.env\n*.md\ndist\n"
}
IMPORTANT:
- "content" must contain the COMPLETE Dockerfile as a string
- Use multi-stage builds for compiled languages
- Run as non-root user
- Pin base image versions (no :latest)
- Respond with valid JSON only, no markdownGiven: "Dockerfile for a Node.js application with multi-stage build"
```json
{
"content": "FROM node:20-alpine AS builder\nWORKDIR /app\nCOPY package*.json ./\nRUN npm ci --only=production\nCOPY . .\nRUN npm run build\n\nFROM node:20-alpine\nRUN addgroup -g 1001 -S appgroup && adduser -u 1001 -S appuser -G appgroup\nWORKDIR /app\nCOPY --from=builder /app/dist ./dist\nCOPY --from=builder /app/node_modules ./node_modules\nCOPY --from=builder /app/package.json ./\nEXPOSE 3000\nHEALTHCHECK CMD wget --no-verbose --tries=1 --spider http://localhost:3000/health || exit 1\nUSER appuser\nCMD [\"node\", \"dist/index.js\"]\n",
"dockerignoreContent": "node_modules\n.git\n.env*\n*.md\nDockerfile\n.dockerignore\ndist\ncoverage\n.nyc_output\n"
}
```- Use specific base image tags (no :latest) - Include HEALTHCHECK for production images - Run as non-root user - Minimize number of layers (combine RUN commands) - Copy dependency files before source for layer caching - No secrets or credentials in the image
No comments yet.
docker, dockerfile, container, image, build, multi-stage, containerize, containerfile, docker-build, registry, push