docker-patterns

Generate multi-stage Dockerfiles and docker-compose configurations with health checks and security hardening.

364|53|Updated May 9, 2026
One-click install
npx skills add https://github.com/cosmicstack-labs/mercury-agent-skills --skill docker-patterns-cosmicstack-labs
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: docker-patterns
Source: https://github.com/cosmicstack-labs/mercury-agent-skills/tree/main/categories/devops/docker-patterns
Command: npx skills add https://github.com/cosmicstack-labs/mercury-agent-skills --skill docker-patterns-cosmicstack-labs

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps you reduce Docker image size, improve build speed, and harden containers by applying proven Dockerfile and docker-compose patterns that prevent common security and operational mistakes.

Core Features & Use Cases

  • Multi-stage Dockerfile design: Separate build and runtime stages so you ship only what you need in production.
  • Cache-efficient and reproducible builds: Structure layers to maximize caching and avoid non-deterministic results.
  • Security hardening: Enforce non-root execution, defense in depth settings, and vulnerability scanning workflows to lower risk before deployment.
  • Docker Compose composition patterns: Configure services with health checks, profiles, secrets, and safer volume usage for realistic multi-service environments.
  • Use Case: When you need to containerize a production API, use these patterns to produce a smaller, faster-to-build, non-root image with a compose setup that waits for healthy dependencies.

Quick Start

Ask the AI to generate an optimized, multi-stage, non-root Dockerfile and a production-ready docker-compose.yml for your application, including .dockerignore, health checks, and a vulnerability scanning step.

Frequently Asked Questions about docker-patterns

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

FAQPage Schema
How do I make my Docker images smaller using multi-stage builds?

Multi-stage builds separate your build environment from your runtime environment so you ship only necessary artifacts. This reduces Docker image size, improves build speed, and limits the attack surface by leaving build tools and dependencies out of production.

How do I configure docker-compose health checks and secrets for a production API?

Configuring docker-compose health checks and secrets ensures your services wait for healthy dependencies before starting. You define health check parameters in your compose file and manage sensitive data using Docker secrets to prevent hardcoding credentials in your orchestration setup.

Does Docker require non-root runtime configuration for container security hardening?

Container security hardening requires non-root runtime configuration to enforce defense-in-depth settings. Running your container as a non-root user prevents privilege escalation attacks and limits the potential damage if an attacker compromises your application.

What is the best way to optimize Dockerfile layer ordering for reproducible builds?

Optimizing Dockerfile layer ordering structures your instructions to maximize caching and avoid non-deterministic results. You place frequently changing application code after stable dependency installation steps to speed up rebuilds and ensure consistent outputs.

Can I use pinned base images to prevent vulnerability scanning failures in Docker?

Pinned base images lock your Docker build to specific, verified versions of your base OS or runtime. This prevents unexpected vulnerability scanning failures caused by upstream changes and ensures reproducible builds across different environments.