当前位置: 首页 > Skill >

docker-plus

docker-plus

1.0.0 2026.11.27 浏览:846
获取Skill文件查看使用说明
作者:许舟许可证:
本文目录展开

Docker Plus

Enhanced Docker with templates, security hardening, and production best practices.

Features

  • Dockerfile Templates: Ready-to-use templates for common languages
  • Multi-stage Builds: Optimize image size
  • Security Hardening: CIS benchmarks, best practices
  • Production Best Practices: Health checks, logging, monitoring
  • Troubleshooting: Common issues and solutions

Quick Reference

Task Command
Build docker build -t app:latest .
Run docker run -d -p 8080:80 app:latest
Logs docker logs -f container_name
Exec docker exec -it container_name sh
Clean docker system prune -af

Dockerfile Templates

Node.js

# Build stage
FROM node:20-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
RUN npm run build

# Production stage
FROM node:20-alpine
WORKDIR /app
RUN addgroup -g 1001 -S nodejs && adduser -S nextjs -u 1001
COPY --from=builder --chown=nextjs:nodejs /app/dist ./dist
COPY --from=builder --chown=nextjs:nodejs /app/node_modules ./node_modules
USER nextjs
EXPOSE 3000
CMD ["node", "dist/index.js"]

Python

# Build stage
FROM python:3.11-slim AS builder
WORKDIR /app
COPY requirements.txt .
RUN pip install --user --no-cache-dir -r requirements.txt

# Production stage
FROM python:3.11-slim
WORKDIR /app
RUN groupadd -r appuser && useradd -r -g appuser appuser
COPY --from=builder /root/.local /root/.local
COPY . .
ENV PATH=/root/.local/bin:$PATH
USER appuser
EXPOSE 8000
CMD ["python", "-m", "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]

Go

# Build stage
FROM golang:1.21-alpine AS builder
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -o main .

# Production stage
FROM alpine:3.18
RUN apk --no-cache add ca-certificates
WORKDIR /root/
COPY --from=builder /app/main .
CMD ["./main"]

Rust

# Build stage
FROM rust:1.72 AS builder
WORKDIR /app
COPY . .
RUN cargo build --release

# Production stage
FROM debian:bookworm-slim
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates && rm -rf /var/lib/apt/lists/*
COPY --from=builder /app/target/release/myapp /usr/local/bin/
CMD ["myapp"]

Multi-Stage Builds

Optimization Pattern

# Stage 1: Dependencies
FROM node:20-alpine AS deps
WORKDIR /app
COPY package*.json ./
RUN npm ci

# Stage 2: Build
FROM node:20-alpine AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
RUN npm run build

# Stage 3: Production
FROM node:20-alpine
WORKDIR /app
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/node_modules ./node_modules
CMD ["node", "dist/index.js"]

Security Hardening

CIS Benchmark Compliance

# Run as non-root
RUN addgroup -g 1001 -S appgroup && adduser -u 1001 -S appuser -G appgroup
USER appuser

# Read-only filesystem
RUN chmod -R 555 /app

# Remove unnecessary packages
RUN apt-get purge -y --auto-remove curl wget

# Set proper permissions
RUN chown -R appuser:appgroup /app

Security Best Practices

# Don't store secrets in image
ARG DB_PASSWORD
ENV DB_PASSWORD=$DB_PASSWORD

# Use specific versions
FROM node:20.10.0-alpine3.18

# Scan for vulnerabilities
RUN apk add --no-cache trivy

# Enable security scanning
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 
  CMD curl -f http://localhost:8080/health || exit 1

Docker Compose Patterns

Production Stack

version: '3.8'

services:
  app:
    build: .
    ports:
      - "8080:8080"
    environment:
      - NODE_ENV=production
      - DATABASE_URL=postgresql://user:pass@db:5432/app
    depends_on:
      db:
        condition: service_healthy
    deploy:
      resources:
        limits:
          cpus: '0.5'
          memory: 512M
    restart: unless-stopped
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
      interval: 30s
      timeout: 10s
      retries: 3

  db:
    image: postgres:15-alpine
    volumes:
      - postgres_data:/var/lib/postgresql/data
    environment:
      - POSTGRES_DB=app
      - POSTGRES_USER=user
      - POSTGRES_PASSWORD=pass
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U user -d app"]
      interval: 10s
      timeout: 5s
      retries: 5

  redis:
    image: redis:7-alpine
    volumes:
      - redis_data:/data

volumes:
  postgres_data:
  redis_data:

Production Best Practices

Health Checks

HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 
  CMD curl -f http://localhost:8080/health || exit 1

Logging

# Use JSON logging
RUN npm install winston

# Log to stdout/stderr
CMD ["node", "dist/index.js"]

Resource Limits

# Run with resource limits
docker run -d 
  --name app 
  --memory="512m" 
  --cpus="0.5" 
  --pids-limit=100 
  -p 8080:8080 
  app:latest

Troubleshooting

Common Issues

Issue Solution
Container exits immediately Check logs: docker logs container_name
Port already in use Stop existing container or change port
OOM killed Increase memory limit
Permission denied Check file ownership and USER directive
DNS resolution fails Use custom network, not default bridge

Debug Commands

# Check container logs
docker logs -f --tail 100 container_name

# Inspect container
docker inspect container_name

# Execute into container
docker exec -it container_name sh

# Check resource usage
docker stats container_name

# View container processes
docker top container_name

Best Practices

  1. Use multi-stage builds - Separate build and runtime
  2. Run as non-root - Security requirement
  3. Set resource limits - Prevent OOM kills
  4. Health checks - Monitor container health
  5. Pin versions - Reproducible builds
  6. Minimize layers - Combine RUN commands
  7. Use .dockerignore - Exclude unnecessary files
  8. Log to stdout/stderr - Container logging best practice

推荐文章

更多
PHP时间戳与日期字符串相互转换方法详解

本文介绍PHP中时间数值(Unix时间戳)与日期字符串之间的相互转换方法。通过strtotime和date函数,实现将当前时间、指定日期转换为时间戳,以及将时间戳格式化为可读的日期时间字符串,并提供相关在线计算工具推荐。

2025.11.30 1,034
PHP日期转时间戳时区偏差怎么解决

在 PHP 中将日期字符串转换为时间戳时,若未显式指定时区,默认使用脚本配置的 date.timezone 或系统时区。当服务器时区与业务逻辑预期(如 UTC )不一致时,会产生偏差。解决核心是确保输入字符串携带明确时区信息,或在转换前统一设置时区上下文。

2026.10.24 1,031
PHP跨域配置:怎么安全地允许指定域名而非使用通配符

在 PHP 中安全地允许指定域名跨域,核心是解析请求头中的 Origin ,验证其是否在白名单内,然后动态设置 Access-Control-Allow-Origin 响应头。不要使用通配符 * ,也不要硬编码单一域名。

2025.03.29 1,018
JavaScript中利用replace结合正则实现replaceAll效果

JavaScript原生仅支持replace()进行单次或全局替换,缺乏类似Java的replaceAll()便捷方法。本文总结四种在JS中实现全量替换的方案:使用带g标志的正则、带gm标志的正则、扩展String原型以及split后join。通过对比代码示例,展示各方法的实现细节与适用场景,帮助开发者根据需求选择最优解。

2025.04.29 1,017
OpenAI的Jalapeno芯片未落地,教你分辨300兆瓦算力消息

OpenAI计划在SB Energy租赁的数据中心部署约300兆瓦自研Jalapeno推理芯片,但目前双方仍处于洽谈阶段,交易细节与上线时间表均未公布。本文带你按报道原文核实项目所处阶段,厘清芯片发布、电力功率与实际推理算力的边界,并将融资意向与签约、开工、投运节点分开追踪,避免误将规划容量计入现有算力。

2026.12.02 1,013
PHP实现基础文件上传:HTML表单与$_FILES处理流程

在 HTML 表单中设置 enctype="multipart/form-data" ,并在 PHP 后端通过 $_FILES 数组接收文件,调用 move_uploaded_file() 将临时文件移动到目标目录即可完成上传。

2026.09.07 1,013
Skill 文件
  • SKILL.md
    • Docker Plus
    • Features
    • Quick Reference
    • Dockerfile Templates
      • Node.js
      • Python
      • Go
      • Rust
    • Multi-Stage Builds
      • Optimization Pattern
    • Security Hardening
      • CIS Benchmark Compliance
      • Security Best Practices
    • Docker Compose Patterns
      • Production Stack
    • Production Best Practices
      • Health Checks
      • Logging
      • Resource Limits
    • Troubleshooting
      • Common Issues
      • Debug Commands
    • Best Practices
  • 项目或源文件

相关 Skill

更多
skill-creator-enhanced skill-creator-enhanced Enhanced skill creator with templates, validation, publishing workflow, and quality gates. Guides through skill creation process with best practices, common patterns, and ClawHub integration.
NextJS Frontend Development + Integration NextJS Frontend Development + Integration Generate production-ready Next.js projects with TypeScript, Tailwind CSS, shadcn/ui, and API integration. Use when the user asks to build, create, develop, or scaffold a Next.js application, web app, full-stack project, or frontend with backend integration. Prioritizes modern stack (Next.js 14+, TypeScript, shadcn/ui, axios, react-query) and best practices. Also triggers on requests to add features, integrate APIs, or extend existing Next.js projects.
Two Factor Authentication Best Practices Two Factor Authentication Best Practices 该技能为使用 Better Auth 的 twoFactor 插件实施安全的双因素认证(2FA)提供指导和强制规则。
HR每日精选日报 HR每日精选日报 Generate a professional HR daily briefing report as a beautifully designed HTML page. Use when the user requests an HR daily report, HR industry news digest, human resources trend analysis, HR best practices compilation, or HR case study review. Covers insights from top consulting firms (McKinsey, Deloitte, BCG, Mercer, WTW), deep dives into HR functional modules (recruitment, performance, compensation, talent development, employee relations, HR planning) and the three-pillar model (HRBP, COE, S
Apply Git branching, commit, and pull request best practices through Git Workflow Skill Apply Git branching, commit, and pull request best practices through Git Workflow Skill 为代理提供一个便携式的 Git 工作流手册,涵盖分支策略、提交规范、拉取请求、合并选择和 CI 敏感协作。