docker-management – skill DevOps & Hạ tầng cho agent AI
Xây dựng, tối ưu và xử lý sự cố container và image Docker.
Cài skill docker-management bằng một lệnh
Chọn công cụ bạn đang dùng, copy lệnh và dán vào terminal. Skill sẽ nằm trong thư mục skills của công cụ đó và sẵn sàng dùng ở phiên làm việc tiếp theo.
Claude Code
mkdir -p ~/.claude/skills && curl -fsSL https://skill.dn1nguoi.com/z/docker-management-d88db.tgz | tar xz -C ~/.claude/skills
Gọi trong Claude Code: /docker-management – rồi mô tả công việc bạn muốn làm.
Codex
mkdir -p ~/.codex/skills && curl -fsSL https://skill.dn1nguoi.com/z/docker-management-d88db.tgz | tar xz -C ~/.codex/skills
Gọi trong Codex: $docker-management – rồi mô tả công việc bạn muốn làm.
Hermes Agent
mkdir -p ~/.hermes/skills && curl -fsSL https://skill.dn1nguoi.com/z/docker-management-d88db.tgz | tar xz -C ~/.hermes/skills
Gọi trong Hermes Agent: /docker-management – rồi mô tả công việc bạn muốn làm.
DeepSeek
mkdir -p ~/.deepcode/skills && curl -fsSL https://skill.dn1nguoi.com/z/docker-management-d88db.tgz | tar xz -C ~/.deepcode/skills
Gọi trong DeepSeek: /docker-management – rồi mô tả công việc bạn muốn làm.
Nội dung SKILL.md
Nội dung SKILL.md gốc bằng tiếng Anh.
Docker Management
Build, run, and manage Docker containers for application deployment and development.
When to Use This Skill
Use this skill when:
- Creating and optimizing Dockerfiles
- Building and tagging Docker images
- Running and managing containers
- Debugging container issues
- Configuring Docker networking and volumes
- Implementing container security best practices
Execution Scope
Confirm the selected Docker context and project before any operation. Build instructions execute contributed commands; inspect the Dockerfile, build context, scripts and downloaded dependencies first. Image publication, shared-container stops and volume deletion need authorization for the exact target. Do not expose environment values, image history or logs containing credentials. These examples are independent fragments with project-specific assets, not a complete deployment.
Prerequisites
- Docker Engine installed (20.10+)
- Basic command line knowledge
- Understanding of application deployment
Dockerfile Best Practices
Multi-Stage Build
# Build stage
FROM node:20-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build && npm prune --omit=dev
# Production stage
FROM node:20-alpine AS production
WORKDIR /app
RUN addgroup -g 1001 -S nodejs && \
adduser -S nodejs -u 1001 -G nodejs
COPY --from=builder --chown=nodejs:nodejs /app/dist ./dist
COPY --from=builder --chown=nodejs:nodejs /app/node_modules ./node_modules
USER nodejs
EXPOSE 3000
CMD ["node", "dist/index.js"]Layer Optimization
FROM python:3.12-slim
# Install dependencies first (cached unless requirements change)
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Copy application code (changes frequently)
COPY . .
CMD ["python", "app.py"]Security Hardening
FROM node:20-alpine
# Create non-root user
RUN addgroup -g 1001 appgroup && \
adduser -u 1001 -G appgroup -D appuser
WORKDIR /app
# Copy with proper ownership
COPY --chown=appuser:appgroup . .
# Drop privileges
USER appuser
# Use exec form for proper signal handling
CMD ["node", "server.js"]Building Images
Basic Build
# Build with tag
docker build -t myapp:1.0 .
# Build with build args
docker build --build-arg NODE_ENV=production -t myapp:prod .
# Build for specific platform
docker build --platform linux/amd64 -t myapp:amd64 .
# Build with no cache
docker build --no-cache -t myapp:fresh .Multi-Platform Builds
# Create builder
docker buildx create --name multiplatform --use
# Build for multiple architectures
docker buildx build \
--platform linux/amd64,linux/arm64 \
-t myregistry/myapp:latest \
--push .Running Containers
Basic Operations
# Run container
docker run -d --name myapp -p 8080:3000 myapp:latest
# Run with environment variables
docker run -d \
-e DATABASE_URL=postgres://localhost/db \
-e NODE_ENV=production \
myapp:latest
# Run with resource limits
docker run -d \
--memory="512m" \
--cpus="1.0" \
myapp:latest
# Run with restart policy
docker run -d --restart=unless-stopped myapp:latestVolume Management
# Named volume
docker volume create mydata
docker run -v mydata:/app/data myapp:latest
# Bind mount
docker run -v "$(pwd)/config:/app/config:ro" myapp:latest
# tmpfs mount (memory)
docker run --tmpfs /tmp:rw,noexec,nosuid myapp:latestNetworking
# Create network
docker network create mynetwork
# Run on network
docker run -d --network mynetwork --name api myapp:latest
# Connect existing container
docker network connect mynetwork existing-container
# Expose specific ports
docker run -d -p 127.0.0.1:8080:3000 myapp:latestContainer Lifecycle
Management Commands
# List containers
docker ps -a
# Stop container
docker stop myapp
# Remove container
docker rm myapp
# Force remove running container
docker rm -f myapp
# Prune stopped containers
docker container prune -fLogs and Monitoring
# View logs
docker logs myapp
# Follow logs
docker logs -f --tail 100 myapp
# View resource usage
docker stats myapp
# Inspect container
docker inspect myappDebugging Containers
Interactive Access
# Execute command in running container
docker exec -it myapp /bin/sh
# Run container with shell
docker run -it --rm myapp:latest /bin/sh
# Debug failed container
docker run -it --entrypoint /bin/sh myapp:latestTroubleshooting
# Check container logs for errors
docker logs myapp 2>&1 | grep -i error
# Inspect container state
docker inspect --format='{{.State.Status}}' myapp
# Check container processes
docker top myapp
# View container filesystem changes
docker diff myapp
# Export container filesystem
docker export myapp > myapp-fs.tarHealth Checks
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD ["node", "-e", "fetch('http://localhost:3000/health').then(r=>process.exit(r.ok?0:1)).catch(()=>process.exit(1))"]# Check health status
docker inspect --format='{{.State.Health.Status}}' myappImage Management
Tagging and Pushing
# Tag image
docker tag myapp:latest myregistry.com/myapp:v1.0
# Push to registry
docker push myregistry.com/myapp:v1.0
# Pull image
docker pull myregistry.com/myapp:v1.0Cleanup
# Remove unused images
docker image prune -a
# Destructive broad cleanup: only after explicit scope approval and verified backups
docker system prune -a --volumes
# Remove specific image
docker rmi myapp:old
# List image sizes
docker images --format "table {{.Repository}}\t{{.Tag}}\t{{.Size}}"Image Analysis
# View image history
docker history myapp:latest
# Inspect image layers
docker inspect myapp:latest
# Check image vulnerabilities (with Docker Scout)
docker scout cves myapp:latestDocker Compose Integration
# docker-compose.yml
services:
app:
build:
context: .
dockerfile: Dockerfile
ports:
- "127.0.0.1:3000:3000"
environment:
- NODE_ENV=production
volumes:
- app-data:/app/data
depends_on:
- db
restart: unless-stopped
db:
image: postgres:15-alpine
environment:
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?set a local fixture password}
volumes:
- db-data:/var/lib/postgresql/data
volumes:
app-data:
db-data:Security Best Practices
Image Security
# Use specific version tags
FROM node:22-alpine
# Don't run as root
USER nobody
# Remove unnecessary packages
RUN apk del --purge .build-deps # only if this virtual build-dependency group was created earlier
# Use COPY instead of ADD
COPY . .Runtime Security
# Run with security options
docker run -d \
--security-opt=no-new-privileges \
--cap-drop=ALL \
--cap-add=NET_BIND_SERVICE \
--read-only \
myapp:latest
# Use user namespace remapping
# Add to /etc/docker/daemon.json: {"userns-remap": "default"}Common Issues
Issue: Container Exits Immediately
Problem: Container starts and stops instantly
Solution: Check if CMD/ENTRYPOINT runs foreground process, use docker logs to see errors
Issue: Cannot Connect to Container
Problem: Port not accessible
Solution: Verify port mapping (-p), check container is running, verify firewall rules
Issue: Out of Disk Space
Problem: Docker using too much disk
Solution: Inspect docker system df and named resources first. Remove only explicitly authorized unused targets; broad volume pruning can destroy data
Issue: Build Cache Not Working
Problem: Every build downloads dependencies
Solution: Order Dockerfile instructions from least to most frequently changing
Best Practices
- Use multi-stage builds to minimize image size
- Never store secrets in images - use runtime injection
- Pin base image versions for reproducibility
- Implement health checks for production containers
- Use .dockerignore to exclude unnecessary files
- Run containers as non-root users
- Scan images for vulnerabilities regularly
- Use Docker BuildKit for faster builds
Related Skills
- docker-compose (
docker-compose) - Multi-container applications - container-scanning (
container-scanning) - Security scanning - container-hardening (
container-hardening) - Security hardening
Limitations
- Guidance executes against real environments: confirm target, blast radius, and rollback plan before applying anything.
- Never deploy to production without explicit approval. Docs-only import: upstream scripts and templates not bundled.
Example
git status && git diff --stat
docker context show
docker compose config --quiet> Adapted from [BagelHole/DevOps-Security-Agent-Skills](https://github.com/BagelHole/DevOps-Security-Agent-Skills) (MIT); frontmatter, When to Use/
… (nội dung đầy đủ có trong gói tải về)
Skill liên quan
- dropthehassle-publish – Xuất bản trang tĩnh đã hoàn thiện lên liên kết HTTPS miễn phí với DropTheHassle: build…
- terraform-module-library – Xây dựng module Terraform tái sử dụng cho AWS, Azure, GCP và OCI theo các thực hành tốt…
- elk-stack – Triển khai và quản lý ELK Stack (Elasticsearch, Logstash, Kibana) để tổng hợp và phân…
- quality-manager-qmr – Quality Manager Responsible Person (QMR) cấp cao cho công ty HealthTech và MedTech. Cung…
- error-diagnostics-error-trace – Bạn là chuyên gia theo dõi lỗi và observability, chuyên triển khai giải pháp giám sát…
- vector-index-tuning – Tối ưu hiệu năng chỉ mục vector về độ trễ, recall và bộ nhớ. Dùng khi tinh chỉnh tham số…
- expo-cicd-workflows – Giúp hiểu và viết file YAML workflow của EAS cho dự án Expo. Dùng skill này khi người…
- expo-deployment – Triển khai ứng dụng Expo với EAS: build và submit bản phát hành iOS và Android, cấu hình…