Coding
docker
containers
devops

Dockerfile Generator

Generate production-ready Dockerfiles with multi-stage builds, security best practices, and optimized layer caching.

The Prompt

(2 messages)
System
You are a DevOps engineer specializing in containerization. Generate production-quality Dockerfiles.

Best practices:
- Use multi-stage builds to minimize image size
- Pin base image versions (not :latest)
- Run as a non-root user
- Order layers from least to most frequently changing for optimal caching
- Use .dockerignore recommendations
- Set appropriate health checks
- Minimize the number of layers
- Don't install unnecessary packages
- Add comments explaining non-obvious decisions
User
Generate a Dockerfile for:

Application: {{application}}
Runtime: {{runtime}}
Requirements: {{requirements}}

Variables

Fill in these inputs to customize your output:

{{application}}

Example: Next.js 15 web application with Prisma ORM

{{runtime}}

Example: Node.js 22

{{requirements}}

Example: Production-optimized, needs prisma generate at build time, standalone output mode, health check endpoint at /api/health

Example Output

Here's what this prompt generates with the sample inputs:

Sample outputgpt-4.1
# --- Build stage ---
FROM node:22-alpine AS base

# Install dependencies only (cache layer)
FROM base AS deps
WORKDIR /app
COPY package.json package-lock.json ./
COPY prisma ./prisma/
RUN npm ci && npx prisma generate

# Build the application
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY --from=deps /app/node_modules/.prisma ./node_modules/.prisma
COPY . .
ENV NEXT_TELEMETRY_DISABLED=1
RUN npm run build

# --- Production stage ---
FROM base AS runner
WORKDIR /app
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1

# Non-root user for security
RUN addgroup --system --gid 1001 nodejs && \
    adduser --system --uid 1001 nextjs

# Copy only what's needed to run
COPY --from=builder /app/public ./public
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
COPY --from=deps /app/node_modules/.prisma ./node_modules/.prisma

USER nextjs
EXPOSE 3000
ENV PORT=3000
ENV HOSTNAME="0.0.0.0"

HEALTHCHECK --interval=30s --timeout=3s --start-period=10s \
  CMD wget --no-verbose --tries=1 --spider http://localhost:3000/api/health || exit 1

CMD ["node", "server.js"]

Configuration

Optimized settings included when you add this prompt. You can adjust them later.

Provider

OPENAI

Model

gpt-4.1

Temperature

0.3

Ready to use this prompt?

Add it to your workspace, customize the inputs, and generate your own results.

Use this prompt — free

More prompts