Dockerfile Patterns
Primary Actions
- Create production-ready Dockerfiles for common language stacks.
- Reduce image size with multi-stage build separation.
- Improve build speed with layer-cache-friendly ordering.
- Apply baseline security hardening defaults.
- Choose fit-for-purpose base images for runtime constraints.
Quick Build Pattern
FROM python:3.11 AS builder
WORKDIR /app
COPY requirements.txt .
RUN pip install --prefix=/install -r requirements.txt
COPY . .
FROM python:3.11-slim
WORKDIR /app
COPY --from=builder /install /usr/local
COPY --from=builder /app /app
RUN useradd -u 1001 -m appuser
USER 1001
ENTRYPOINT ["python", "-m", "myapp"]
Validation Workflow
- Build the image (
docker build). - Run startup check (
docker run --rm <image> --helpor equivalent). - For services, run a smoke check with expected command/port.
- Run vulnerability scan before release (
trivy imageordocker scout cves). - If validation fails, revise Dockerfile and rebuild.
Language Templates
- assets/python-dockerfile.dockerfile
- assets/node-dockerfile.dockerfile
- assets/rust-dockerfile.dockerfile
- assets/r-dockerfile.dockerfile
Deep References
- Multi-stage design patterns: references/multi-stage-builds.md
- Layer caching patterns and cache debugging: references/layer-caching.md
- Base image selection decision guidance: references/base-image-selection.md
- Validation gates,
.dockerignore, security defaults, and common failure patterns: references/build-validation-and-ops.md
Source: yongsinp/rse-plugins — distributed by TomeVault.