docker-best-practices

Apply Dockerfile best practices for multi-stage builds, non-root users, and pinned versions.

Updated Jan 15, 2026
One-click install
npx skills add https://github.com/rory-data/copilot --skill docker-best-practices-rory-data
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: docker-best-practices
Source: https://github.com/rory-data/copilot/tree/main/skills/docker-best-practices
Command: npx skills add https://github.com/rory-data/copilot --skill docker-best-practices-rory-data

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Docker image builds are error-prone and hard to audit; this Skill codifies best practices to improve security, performance, and maintainability.

Core Features & Use Cases

  • Multi-stage builds: Separate build and runtime dependencies
  • Non-root users & pinned versions: Reduce attack surface and ensure reproducibility
  • Base image optimization: Prefer Alpine/slim images and avoid the latest tag for reliability

Quick Start

Review a Dockerfile and apply the listed best practices to produce a secure, efficient image.

Frequently Asked Questions about docker-best-practices

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

FAQPage Schema
How do I make Docker images more secure and efficient?

Make Docker images more secure by applying standard Dockerfile best practices: enforce multi-stage builds, use non-root users, pin dependency versions, and select minimal base images like Alpine or slim to reduce the attack surface and ensure reproducibility.

What is a multi-stage build in Docker and when should I use it?

A multi-stage build in Docker separates build dependencies from the final runtime image. Use multi-stage builds to compile binaries with heavy toolchains first, then copy only the artifacts into a minimal base image, reducing final image size and potential vulnerabilities.

How do I write a Dockerfile with a non-root user?

To write a Dockerfile with a non-root user, create a dedicated user inside the image and switch to it using the USER instruction. Running containers as a non-root user prevents privilege escalation attacks and improves overall container security.

Why should I avoid the latest tag in Docker base images?

Avoid the latest tag in Docker base images because it points to unpredictable versions that change over time. Pinning specific image versions or digests ensures reproducible builds and prevents unexpected breaking changes from upstream updates.

What is the best way to optimize Docker images for CI pipelines?

The best way to optimize Docker images for CI pipelines is enforcing multi-stage builds, pinned versions, and minimal base images like Alpine or slim. These practices ensure reproducible, efficient builds and reduce security vulnerabilities in automated deployment configurations.

Does using Alpine or slim base images work for all containerized apps?

Using Alpine or slim base images works for many containerized apps but may cause compatibility issues with binaries relying on glibc. Choose minimal base images to improve efficiency, but verify application dependencies to ensure runtime compatibility.