writing-dockerfiles

Optimize Dockerfile creation with multi-stage builds and security hardening.

2|2|Updated Feb 9, 2017
One-click install
npx skills add https://github.com/sumik5/dotfiles --skill writing-dockerfiles
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: writing-dockerfiles
Source: https://github.com/sumik5/dotfiles/tree/main/claude-code/skills/writing-dockerfiles
Command: npx skills add https://github.com/sumik5/dotfiles --skill writing-dockerfiles

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill guides Dockerfile creation with multi-stage builds, caching, security hardening, and image size minimization.

Core Features & Use Cases

  • Multi-stage builds: Separate build and runtime stages for smaller images.
  • Caching strategies: Layer optimization and ordering for caching.
  • Security hardening: Non-root usage and distroless images.

Quick Start

Create a Dockerfile for a simple Node app using multi-stage build.

Frequently Asked Questions about writing-dockerfiles

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

FAQPage Schema
How do I reduce Docker image size with multi-stage builds?

Multi-stage builds separate compilation from runtime by using multiple FROM statements in a single Dockerfile. Build dependencies and artifacts are created in an early stage, then only necessary files are copied to the final stage, significantly reducing image size without including build tools in production.

What are Docker layer caching best practices for faster builds?

Docker layer caching works by reusing unchanged layers from previous builds. Order Dockerfile instructions from least to most frequently changing—place stable dependencies early and volatile application code late. This maximizes cache hits and accelerates rebuilds when only application code changes.

How do I harden Dockerfiles for security?

Security hardening includes running containers as non-root users, using distroless base images to minimize attack surface, scanning for vulnerabilities with linting tools, and applying principle of least privilege. These practices reduce exposure to container breakout and supply-chain attacks.

What's the difference between ENTRYPOINT and CMD in a Dockerfile?

ENTRYPOINT defines the command that always runs when a container starts, while CMD provides default arguments to that command. Use ENTRYPOINT for the main process and CMD for configurable parameters, allowing flexibility when users override behavior at runtime.

Can I use multi-stage builds with Docker Compose?

Yes. Docker Compose recognizes and executes multi-stage Dockerfiles in services. When you build through Compose, it respects all stages and produces final images optimized by your staging strategy, making Compose deployments benefit from the same size and security gains.