writing-dockerfiles

Write optimized multi-stage Dockerfiles with language-specific patterns and BuildKit features.

1|Updated Feb 24, 2026
One-click install
npx skills add https://github.com/masermediagroup-stack/maser-media --skill writing-dockerfiles-masermediagroup-stack
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: writing-dockerfiles
Source: https://github.com/masermediagroup-stack/maser-media/tree/main/.cursor/skills/community/ai-design-components/skills/writing-dockerfiles
Command: npx skills add https://github.com/masermediagroup-stack/maser-media --skill writing-dockerfiles-masermediagroup-stack

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) components.

What problem does it solve? Containerizing applications often results in bloated, insecure images with slow builds and leaked secrets. This Skill provides production-grade Dockerfile patterns that reduce image sizes by 80-95%, enforce security hardening, and accelerate builds through BuildKit caching. ## Core Features & Use Cases - Language-Specific Patterns: Ready-to-use multi-stage Dockerfile templates for Python, Node.js, Go, Rust, and Java with correct base image selection (slim, alpine, distroless, scratch). - BuildKit Optimization: Cache mounts for package managers (pip, npm, go mod, cargo), secret mounts for credentials, and SSH mounts for private repositories. - Security Hardening: Non-root user configuration, distroless runtime images, vulnerability scanning with Trivy, and .dockerignore templates to prevent secret leaks. - Use Case: A Go microservice needs containerization for production. The Skill produces a multi-stage Dockerfile compiling a static binary with CGO disabled, running on distroless/static as nonroot, yielding a 10-30MB image. ## Quick Start Write an optimized multi-stage Dockerfile for my Python FastAPI application with a non-root user and BuildKit cache mounts.

Frequently Asked Questions about writing-dockerfiles

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write a multi-stage Dockerfile to reduce image size?▼

Use a builder stage with the full language image to compile or install dependencies, then copy only the artifacts into a minimal runtime stage like distroless or alpine. This excludes build tools from the final image, typically reducing size by 80-95%.

What base image should I use for a Go application in Docker?▼

Build with golang:1.22-alpine using CGO_ENABLED=0 for a static binary, then run on gcr.io/distroless/static-debian12 for a 10-30MB image. Use scratch for ultra-minimal images if you copy CA certificates separately.

How do I use secrets in Docker builds without leaking them?▼

Use BuildKit secret mounts with RUN --mount=type=secret,id=my_token, which makes the secret available only during that RUN command without storing it in image layers. Pass secrets at build time with docker buildx build --secret id=my_token,src=token.txt.

Should I use alpine or slim base images for Python?▼

Use python:3.12-slim for Python production images because alpine uses musl libc instead of glibc, causing compiled packages like numpy and pandas to build from source. Alpine works well for Node.js and Go build stages.

Why is my Docker build slow and how do I speed it up?▼

Slow builds usually come from re-downloading packages on every build. Enable BuildKit and add cache mounts like --mount=type=cache,target=/root/.npm for npm or /go/pkg/mod for Go, giving 10-100x faster rebuilds on cache hits.

How do I run a Docker container as a non-root user?▼

Create a user with useradd or adduser in the Dockerfile and switch with the USER instruction before CMD. Distroless images include a built-in nonroot user (UID 65532), and official Node images include a node user (UID 1000).