AGENT SKILL

trove-docker

Dockerfile and Docker Compose best practices. Auto-activates on Docker files.

License 许可
MIT
所属仓库
bravew/trove
最近更新
2026-11-12
Stars
★ 10
Forks
1

01 前言 Front Matter

name
trove-docker
paths
[ "**/Dockerfile*", "**/docker-compose*.yml" ]
metadata
{ "trove-category": "servers-cloud", "trove-category-label": "Servers & cloud" }
description
Dockerfile and Docker Compose best practices. Auto-activates on Docker files.

03 SKILL.md 正文

<!-- AUTO-GENERATED from SKILL.md.tmpl — do not edit directly --> <!-- Regenerate: bun run build:skills -->

Session Init

This skill ships Trove conventions. Prefer existing project patterns over generic best practices when they conflict.

Docker Conventions

Dockerfile Best Practices

# Use specific version tags, not :latest
FROM python:3.13-slim AS base

# Set working directory early
WORKDIR /app

# Copy dependency files first (cache layer)
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Copy application code last (changes most often)
COPY . .

# Run as non-root user
RUN adduser --disabled-password --gecos '' appuser
USER appuser

EXPOSE 8000
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]

Multi-Stage Builds

Use multi-stage builds to reduce image size:

FROM node:22-alpine AS builder
WORKDIR /app
COPY package.json pnpm-lock.yaml ./
RUN pnpm install --frozen-lockfile
COPY . .
RUN pnpm build

FROM nginx:alpine
COPY --from=builder /app/dist /usr/share/nginx/html

AI Gotchas

  • Layer caching: Order instructions from least to most frequently changing
  • COPY vs ADD: Use COPY unless you need URL download or tar extraction
  • HEALTHCHECK: Always include for production images
  • .dockerignore: Exclude node_modules, .git, .env, test files

04 同仓库更多 Skills