docker

Optimize Dockerfiles and Compose files for secure, cache-friendly images.

Updated Mar 1, 2026
One-click install
npx skills add https://github.com/CloudyWing/ai-dotfiles --skill docker-cloudywing
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: docker
Source: https://github.com/CloudyWing/ai-dotfiles/tree/main/skills/docker
Command: npx skills add https://github.com/CloudyWing/ai-dotfiles --skill docker-cloudywing

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill enforces Dockerfile and Docker Compose best practices to produce secure, small, and cache-efficient container images while avoiding common pitfalls like running as root, poor layer caching, missing health checks, and improper Compose syntax.

Core Features & Use Cases

  • Multi-stage build guidance with .NET-specific conventions: separate build and runtime stages, use sdk for build and aspnet/runtime for final stage, and keep versions aligned.
  • Layer caching and .dockerignore recommendations: copy project files individually to maximize restore cache hits, place infrequently changed steps earlier, and exclude build artifacts from context.
  • Runtime safety and deployment readiness: enforce non-root execution, include HEALTHCHECK instructions, avoid hard-coded secrets, and require explicit, versioned image tags plus Compose Specification v2 compliance for CI and production deployments.
  • Use Case: Harden a multi-project .NET solution Dockerfile and compose manifests for CI pipelines and production deployment.

Quick Start

Create a multi-stage Dockerfile for a .NET web app that copies each project file then restores to preserve cache, uses matching sdk and runtime images, switches to a non-root user, includes a HEALTHCHECK, and produce a Compose v2 service with explicit versioned image tags.

Frequently Asked Questions about docker

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

FAQPage Schema
How do I optimize Dockerfiles for smaller and more secure container images?

Optimize Dockerfiles by applying multi-stage builds, matching runtime versions, enforcing non-root execution, and using a .dockerignore file to reduce build context. This approach produces smaller, secure, and cache-friendly container images.

What is the best way to cache Docker layers for .NET multi-project builds?

To cache Docker layers effectively for .NET multi-project builds, copy project files individually before restoring dependencies to maximize cache hits. Place infrequently changed Dockerfile steps earlier to preserve the Docker layer cache.

Does Docker Compose Specification v2 require explicit versioned image tags?

Yes, Docker Compose Specification v2 compliance requires explicit versioned image tags for CI and production deployments. Using versioned tags ensures deployment readiness and prevents unexpected runtime environment changes.

Why does my Dockerfile run as root and how do I fix it?

Dockerfiles run as root by default if not explicitly configured. Fix this by switching to a non-root user in the final runtime stage to enforce runtime safety and meet deployment readiness requirements.

How do I add a HEALTHCHECK to a Docker Compose service?

Add a HEALTHCHECK instruction to your Dockerfile and configure the corresponding health check parameters in your Docker Compose service. This ensures runtime safety and deployment readiness for your web services.

Can I use Docker multi-stage builds for .NET web apps in CI pipelines?

Yes, you can use Docker multi-stage builds for .NET web apps in CI pipelines by separating build and runtime stages. Use the sdk image for building and the aspnet or runtime image for the final stage while keeping versions aligned.