docker-best-practices

Codify Docker best practices for building and securing images.

Updated Aug 27, 2026
One-click install
npx skills add https://github.com/d3fvxl/.dotfiles --skill docker-best-practices-d3fvxl
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: docker-best-practices
Source: https://github.com/d3fvxl/.dotfiles/tree/main/config/opencode/skills/docker-best-practices
Command: npx skills add https://github.com/d3fvxl/.dotfiles --skill docker-best-practices-d3fvxl

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Docker and container best practices. Load when writing Dockerfiles, building images, or containerizing applications. Triggers: Dockerfile, docker build, multi-stage builds, layer caching, image optimization, container security, or docker-compose configuration.

Core Features & Use Cases

  • Multi-Stage Builds: Reduce final image size by separating build-time and runtime
  • Layer Caching & BuildKit: Speed up builds and improve reproducibility
  • Base Image Selection: Pin and choose minimal, appropriate bases
  • Security Hardening: Non-root execution, read-only filesystem, avoid secrets
  • Image Scanning: Integrate vulnerability scanning into the pipeline
  • .dockerignore: Exclude unnecessary files from build context
  • CI/CD Integration: Automate builds, tagging, and deployment
  • Docker-Compose Guidance: Local development and orchestration patterns

Quick Start

Apply the Docker best-practices patterns to your Dockerfiles and CI/CD pipelines to optimize size, security, and build performance.

Frequently Asked Questions about docker-best-practices

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

FAQPage Schema
How do I optimize Docker image size using multi-stage builds?

Multi-stage builds reduce Docker image size by separating build-time dependencies from runtime requirements, copying only necessary artifacts into the final stage. This pattern minimizes the final image footprint and attack surface.

How does BuildKit improve Docker layer caching?

BuildKit speeds up Docker builds by parallelizing independent build stages and intelligently caching layers. It improves build reproducibility and skips unchanged steps, significantly reducing build times in CI/CD pipelines.

What are the best practices for Docker container security hardening?

Docker container security hardening involves running containers as non-root users, enforcing read-only filesystems, and avoiding baked-in secrets. Integrating vulnerability scanning into the pipeline further identifies image risks.

Why do I need a .dockerignore file in my build context?

A .dockerignore file excludes unnecessary files and directories from the Docker build context. This prevents large or sensitive local files from being sent to the daemon, speeding up builds and reducing image bloat.

Can I integrate Docker vulnerability scanning into my CI/CD pipeline?

Vulnerability scanning integrates directly into CI/CD pipelines to automate security checks during image builds. This ensures containers are scanned for known risks before tagging and deployment, catching issues early.

Does this Docker best practices guidance work with docker-compose configurations?

The guidance applies to docker-compose configurations by providing patterns for local development and orchestration. It standardizes container definitions while ensuring minimal bases, health checks, and security practices are maintained.