Docker Container Builder
Generates production-ready, optimized Dockerfiles with multi-stage builds, caching, and tagging for any application.
// prompt
You are a senior DevOps engineer specializing in container image optimization. Build a production-ready Docker setup for the application **{{application_name}}**.
## Application Context
- **Language / runtime:** {{language_and_version}}
- **Build / dependency tool:** {{build_tool_eg_npm_pip_maven_go_modules}}
- **Listening port(s):** {{exposed_port}}
- **Runtime requirements:** {{special_requirements_eg_system_libs_env_vars_secrets}}
- **Target registry & tag scheme:** {{registry_tag_convention}}
## What to Deliver
1. **Multi-stage Dockerfile** — separate build and runtime stages so the final image ships only what it needs to run.
2. **Optimized base images** — pick minimal, supported bases (slim/alpine/distroless where appropriate) and pin versions explicitly. Justify each choice in one line.
3. **Layer caching** — order instructions so dependency manifests are copied and installed before source code, maximizing cache reuse on rebuilds.
4. **Security hardening** — run as a non-root user, avoid leaking secrets into layers, and use `.dockerignore` to exclude build artifacts and local config.
5. **Runtime config** — set required `ENV` variables, `EXPOSE` the correct port, and define a clear `ENTRYPOINT`/`CMD`. Add a `HEALTHCHECK` if relevant.
6. **Tagging & build commands** — provide the `docker build` and `docker tag` commands using semantic version + name (e.g. `name:1.2.0`, `name:latest`).
## Output Format
For each artifact, return:
- A short rationale (2-3 sentences) explaining the design decisions.
- The complete file in a fenced code block (`Dockerfile`, `.dockerignore`).
- The exact build, tag, and run commands.
- A brief note on the expected final image size and how it was reduced.
Constraints: keep the final image as small as possible without sacrificing reproducibility, comment any non-obvious instruction inline, and flag any assumption you had to make about {{application_name}}. Ask me for missing details before generating if a required field above is unclear.
Fill in the variables
Example response
Complete Dockerfile for Node.js App
# Dockerfile for my-node-app
FROM node:18-alpine
# Set working directory
WORKDIR /app
# Copy package files for caching
COPY package*.json ./
# Install dependencies
RUN npm ci --only=production && npm cache clean --force
# Copy application code
COPY . .
# Create non-root user
RUN addgroup -g 1001 -S nodejs
RUN adduser -S nextjs -u 1001
USER nextjs
# Expose port
EXPOSE 3000
# Start application
CMD ["npm", "start"]
Build and Tag Commands
docker build -t my-node-app:v1.0 .
docker tag my-node-app:v1.0 my-node-app:latest
Optimization Features
- Multi-stage builds for smaller images
- Layer caching with package.json copy first
- Non-root user for security
- Alpine base for minimal size
Related prompts
IT & Administration
Cloud Infrastructure Architect
Design a scalable, secure, cost-optimized cloud architecture with IaC, diagrams, and a phased rollout plan.
IT & Administration
Cybersecurity Audit Specialist
Run a structured cybersecurity audit of an organization, prioritizing risks and producing an actionable remediation roadmap.
IT & Administration
DevOps Automation Specialist
Acts as a DevOps engineer to design, optimize, and troubleshoot CI/CD pipelines, infrastructure as code, and cloud automation.
IT & Administration
Ansible Automation Playbook Creator
Generates production-ready, idempotent Ansible playbooks and roles for any infrastructure automation or configuration task.