
docker-storage
Guidance for Docker storage and data persistence. Covers storage types (Volume/Bind Mount/Tmpfs) with comparison and use-case selection, volume lifecycle management (create/ls/inspect/prune), bind mount patterns, tmpfs for ephemeral data, backup and restore strategies, storage driver selection (overlay2), database persistence best practices (PostgreSQL/MySQL/Redis), and NFS/cloud storage integration. Use when the user asks about docker volume, data persistence, bind mount, tmpfs, storage driver, backup, data volume, or needs persistent storage for containers. 使用场景:docker volume、数据持久化、bind mount、tmpfs、存储驱动、数据卷、备份恢复、数据库持久化.
- Installs
- 103
- Last 24h
- —
- Trending rank
- —
- Security
- Not audited
Install
Works with every agent the skills CLI supports.
npx skills add https://github.com/full-stack-skills/docker-skills --skill docker-storage- 01
Install
Run the command in your project. The CLI asks which agents to install for.
- 02
Describe the task
Ask your agent for something this skill covers. It loads docker-storage automatically when relevant.
- 03
Review the result
The agent follows the SKILL.md steps, scripts and references bundled with the skill.
SKILL.md
The instructions your agent reads when the skill is triggered.
Docker Storage — 存储与数据持久化
Comprehensive guidance for managing persistent data in Docker.
When to Use
ALWAYS use this skill when the user mentions:
- "docker volume", "数据卷", "数据持久化"
- "bind mount", "tmpfs"
- "容器数据怎么保存", "数据不丢失"
- "数据库容器怎么持久化"
- "备份恢复", "存储驱动"
Storage Type Comparison
| Type | Persistence | Performance | Use Case |
|---|---|---|---|
| Volume | ✅ (managed by Docker) | High (native) | Production databases, shared data |
| Bind Mount | ✅ (host filesystem) | High | Development (live code sync), config files |
| Tmpfs | ❌ (memory only) | Highest | Secrets, temp files, sensitive data |
Visual Comparison
Volume: Bind Mount: Tmpfs:
Container Container Container
│ │ │
Docker-managed /host/path Memory only
/var/lib/docker/volumes/ ↕ (no disk)
↕ Container sees: ↕
Container sees: /container/path Container sees:
/data = host files /tmp (in RAM)
Volume Management
# Create & inspect
docker volume create mydata
docker volume ls
docker volume inspect mydata
# Use in container
docker run -v mydata:/var/lib/mysql mysql:8
docker run --mount source=mydata,target=/var/lib/mysql mysql:8 # explicit syntax (recommended)
# Cleanup
docker volume prune # Remove unused volumes
docker volume rm mydata # Remove specific volume
Named vs Anonymous Volumes
-v mydata:/data → Named volume (mydata) — survives container removal ✅
-v /data → Anonymous volume — hard to identify later ❌
Bind Mount
# Read-write bind mount
docker run -v $(pwd)/app:/app nginx
# Read-only (protect host files)
docker run -v $(pwd)/config:/etc/nginx:ro nginx
# Explicit syntax
docker run --mount type=bind,source=$(pwd)/app,target=/app nginx
Tmpfs (Memory)
# Ephemeral data, never touches disk
docker run --tmpfs /tmp:rw,noexec,nosuid,size=64m nginx
docker run --mount type=tmpfs,destination=/tmp,tmpfs-size=64m nginx
Database Persistence Patterns
PostgreSQL
docker volume create pgdata
docker run -d \
--name postgres \
-e POSTGRES_PASSWORD=secret \
-v pgdata:/var/lib/postgresql/data \
-p 5432:5432 \
postgres:16-alpine
MySQL
docker volume create mysqldata
docker run -d \
--name mysql \
-e MYSQL_ROOT_PASSWORD=secret \
-v mysqldata:/var/lib/mysql \
-v $(pwd)/my.cnf:/etc/mysql/conf.d/my.cnf:ro \
-p 3306:3306 \
mysql:8.4
Redis (Persistence)
docker volume create redisdata
docker run -d \
--name redis \
-v redisdata:/data \
-p 6379:6379 \
redis:7-alpine redis-server --appendonly yes
Backup & Restore
# Backup (using a temporary container)
docker run --rm \
-v mysqldata:/source \
-v $(pwd):/backup \
alpine tar czf /backup/mysqldata-backup.tar.gz -C /source .
# Restore
docker run --rm \
-v mysqldata:/target \
-v $(pwd):/backup \
alpine tar xzf /backup/mysqldata-backup.tar.gz -C /target
Storage Drivers
| Driver | Status | Notes |
|---|---|---|
| overlay2 | ✅ Default | Best for most use cases; copy-on-write |
| devicemapper | Deprecated | - |
| aufs | Deprecated | - |
| btrfs/zfs | Niche | Use if filesystem matches |
docker info | grep "Storage Driver" # Check current
Workflow — 推荐配置流程
Step 1: 确定存储类型: 持久化数据 → Volume;开发热加载 → Bind Mount;临时缓存 → tmpfs
Step 2: 创建 Volume: docker volume create db_data
Step 3: 挂载到容器: docker run -v db_data:/var/lib/mysql mysql
Step 4: 验证: docker volume inspect db_data + docker exec mysql ls /var/lib/mysql
Step 5: 备份: docker run --rm -v db_data:/source -v $(pwd):/backup alpine tar czf /backup/db.tar.gz -C /source .
Gotchas — Common Pitfalls
- Anonymous volumes accumulate: Every
-v /data(no name) creates a new anonymous volume. → Recovery:docker volume prunecleans all unused; use named volumes:-v mydata:/data. - Bind mount paths: Must be absolute. → Recovery:
-v $(pwd)/app:/appfor docker run;-v ./app:/appworks in Compose only. - Permission issues with bind mounts: Container UID != host UID → permission denied. → Recovery:
--user $(id -u):$(id -g)orRUN chown 1000:1000 /datain Dockerfile entrypoint. - Data loss on container removal: Without
-v, data is lost when container is removed.--rmflag even worse. → Recovery: Always use named volumes:docker run -v db_data:/var/lib/mysql. - macOS bind mount performance: Bind mounts on Docker Desktop Mac are slow. → Recovery: Use
:cachedor:delegatedmount options, or named volumes for better I/O.
Boundary — 能力边界(适用与不适用场景)
| 分类 | 场景 | 说明 |
|---|---|---|
| ✅ 能做 | 数据持久化配置(Volume/Bind Mount/tmpfs) | 三类存储的创建、挂载、管理 |
| ✅ 能做 | 备份与恢复 | tar + --volumes-from 备份恢复 |
| ✅ 能做 | 存储驱动选型 | overlay2/btrfs/zfs 对比 |
| ⚠️ 需条件 | NFS/云存储 Volume 驱动 | 需安装对应驱动插件 |
| ⚠️ 需条件 | macOS 下 Bind Mount 性能 | 使用 :cached/:delegated 或命名 Volume |
| ❌ 超范围 | K8s PersistentVolume/PVC | 使用 docker-production + K8s 文档 |
| ❌ 超范围 | 分布式文件系统(Ceph/GlusterFS) | 系统管理员范畴 |
| ❌ 超范围 | 数据库性能优化 | DBA 专业领域 |
When NOT to Use This Skill
| ❌ Skip | ✅ Use Instead |
|---|---|
| Running containers (no data concerns) | docker-run |
| Multi-container orchestration | docker-compose |
| Kubernetes Storage (PV/PVC) | K8s documentation |
| Docker basics | docker-basics |
Security & Stability
- Use
:rofor config files that containers should not modify. - Never bind mount Docker socket (
/var/run/docker.sock) without understanding the security implications. - Backup volumes regularly, especially database volumes.
- No executable scripts bundled. Guidance only.
📚 官方文档参考
🧭 Docker Skills Journey
📍 You are here:
docker-storage— 数据持久化
← Previous: docker-run / docker-networking
→ Next: docker-compose / docker-security
FAQ
Q1: 如何快速上手此技能? A: 参考上方的快速开始章节,按步骤操作即可。
Q2: 遇到版本不兼容问题怎么办? A: 检查依赖版本,使用 lock 文件锁定,参考常见陷阱章节。
Q3: 如何在生产环境使用? A: 参考最佳实践章节,确保配置正确,做好监控和日志。
Q4: 性能如何优化? A: 参考性能优化相关文档,使用缓存、索引等手段。
Q5: 如何贡献或反馈问题? A: 在 GitHub 仓库提交 Issue 或 Pull Request。
Q6: 是否支持中文? A: 支持中文文档和中文注释,详见国内适配章节。
FAQ
What does the docker-storage skill do?
Guidance for Docker storage and data persistence. Covers storage types (Volume/Bind Mount/Tmpfs) with comparison and use-case selection, volume lifecycle management (create/ls/inspect/prune), bind mount patterns, tmpfs for ephemeral data, backup and restore strategies, storage driver selection (overlay2), database persistence best practices (PostgreSQL/MySQL/Redis), and NFS/cloud storage integration. Use when the user asks about docker volume, data persistence, bind mount, tmpfs, storage driver, backup, data volume, or needs persistent storage for containers. 使用场景:docker volume、数据持久化、bind mount、tmpfs、存储驱动、数据卷、备份恢复、数据库持久化.
How do I install docker-storage?
Run npx skills add https://github.com/full-stack-skills/docker-skills --skill docker-storage in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/docker-storage/ (personal) or .claude/skills/docker-storage/ (project).
Which AI agents can use docker-storage?
Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.
Is docker-storage safe to install?
No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.
Who maintains docker-storage?
It is published by full-stack-skills in full-stack-skills/docker-skills. It has 103 recorded installs.
More from full-stack-skills/docker-skills
docker-compose
full-stack-skills/docker-skills
Expert guidance for Docker Compose — writing production-grade compose.yml files for multi-container applications. Covers complete Compose file syntax (services, networks, volumes, secrets, configs, profiles, extends, include), service configuration (image/build, ports, environment, envfile, dependson with health checks, deploy resources, restart policies), networking in Compose (default networks, custom networks, internal networks), volume management, environment variable strategies (.env vs environment vs envfile), override files for multi-environment, profiles for optional services, and migration to Kubernetes with kompose. Use when the user asks about docker compose, docker-compose.yml, compose file, multi-container, service orchestration, compose configuration, or needs to write/modify a compose file. 使用场景:docker compose、docker-compose.yml、compose 文件、多容器、服务编排、compose 配置、dependson、profiles.
docker-dockerfile
full-stack-skills/docker-skills
Expert guidance for Dockerfile authoring — the complete reference for writing production-grade Dockerfiles. Covers every instruction (FROM/RUN/COPY/ADD/ENV/ARG/WORKDIR/EXPOSE/CMD/ENTRYPOINT/USER/HEALTHCHECK/SHELL) with syntax, best practices, and common mistakes. Includes multi-stage build patterns (build+scratch, build+alpine, builder pattern), layer caching optimization strategies, .dockerignore rules, and language-specific production templates (Go/Rust/Java Spring Boot/Python FastAPI/Node.js Express/TypeScript). Use when the user asks about Dockerfile, how to write a Dockerfile, multi-stage build, layer optimization, or needs Dockerfile examples for a specific language. 使用场景:Dockerfile 编写、怎么写 Dockerfile、Dockerfile 指令、多阶段构建、multi-stage、层优化、layer cache、Dockerfile 模板.
docker-security
full-stack-skills/docker-skills
Guidance for Docker security hardening across the full lifecycle — image security (minimal base images, non-root users, pinned versions), runtime security (seccomp/AppArmor/SELinux, capabilities, read-only rootfs, no-new-privileges), secrets management (BuildKit secrets, Docker secrets in Swarm), Docker Bench Security auditing, CIS compliance checklist, and supply-chain security (image signing, content trust, SBOM). Use when the user asks about Docker security, image hardening, non-root containers, seccomp, AppArmor, Docker Bench, secrets management, or securing containers. 使用场景:docker 安全、镜像安全、非root运行、seccomp、AppArmor、security、Docker Bench、secret管理.
docker-troubleshooting
full-stack-skills/docker-skills
Open the skill to read its SKILL.md instructions.
docker-networking
full-stack-skills/docker-skills
Guidance for Docker networking configuration and inter-container communication. Covers network modes (bridge/host/overlay/none/macvlan/ipvlan), custom bridge networks with DNS resolution, port publishing (-p/--publish), container linking and service discovery, network troubleshooting (inspect/ping/nslookup), overlay networks for Swarm, and network security (internal networks, encrypted overlay). Use when the user asks about docker network, container networking, bridge mode, port mapping, inter-container communication, network troubleshooting, or Docker network modes. 使用场景:docker network、容器网络、bridge、overlay、端口映射、容器通信、网络配置、网络排查.
docker-basics
full-stack-skills/docker-skills
Docker entry point — provides comprehensive guidance for Docker concepts, architecture, and basic operations. Covers what Docker is, container vs VM comparison, Docker architecture (Client-Server, daemon, registry), installation guidance for Linux/Mac/Windows, and first-container walkthrough. Includes Docker object model (Image/Container/Registry/Engine), CLI basics, and the Docker ecosystem overview. Use when the user asks about Docker basics, needs to understand Docker concepts, is new to Docker, or wants containerization fundamentals. 使用场景:Docker 入门、什么是 Docker、容器概念、Docker vs VM、Docker 安装、docker 基础命令、container basics、Docker 架构.
Popular devops & cloud skills
microsoft-foundry
microsoft/azure-skills
Build, deploy, evaluate, optimize, fine-tune, and manage Microsoft Foundry agents, models, and resources end to end. USE FOR: foundry, azd ai agent, azd provision/deploy, hosted agent scaffold/develop/run/deploy/troubleshoot, prompt agent create, managed harness agent create, GitHub Copilot harness agent, create agent, update agent, add tool to agent, invoke agent, agent insights, evaluate agent, batch eval, continuous eval, continuous monitoring, agent CI/CD, optimize prompt, improve prompt, optimize agent instructions, Agent Optimizer scaffold, dataset curation from traces, deploy model, model fine-tuning (SFT/DPO/RFT), Foundry project, RBAC, role assignment, permissions, quota, capacity, region, deployment failure, AI Services, create Foundry resource, knowledge index, customize deployment, onboard, availability, training-data, grader, distillation, large file upload. DO NOT USE FOR: Azure Functions, App Service, general Azure deploy (use azure-deploy), general Azure prep (use azure
azure-diagnostics
microsoft/azure-skills
Debug Azure production issues on Azure using AppLens, Azure Monitor, resource health, and safe triage. WHEN: debug production issues, troubleshoot app service, app service high CPU, app service deployment failure, troubleshoot container apps, container app 503 or target port mismatch, troubleshoot functions, function telemetry missing or stopped after a config/connection-string change, troubleshoot AKS, VM RDP, Linux SSH, VM black screen, can't connect to VM, reset VM password, NSG or firewall blocking, kubectl cannot connect, kube-system/CoreDNS failures, pod pending, crashloop, node not ready, upgrade failures, analyze logs, KQL, insights, image pull failures, cold start issues, health probe failures, resource health, root cause of errors, troubleshoot event hubs, troubleshoot service bus, messaging SDK error, AMQP connection failure, message lock lost, lock renewal during long-running processing, service bus dead letter.
azure-prepare
microsoft/azure-skills
Prepare azd-based Azure projects for deployment: generates azure.yaml, infrastructure (Bicep/Terraform), and Dockerfiles for the Azure Developer CLI (azd) workflow. USE ONLY when the user explicitly wants to use azd as the deployment tool, or the project already has an azure.yaml file. DO NOT USE FOR: non-azd deployments, Python App Service code-only deploys (use python-appservice-deploy), or cross-cloud migration (use azure-cloud-migrate). WHEN: prepare app for azd, create azure.yaml, set up azd infrastructure, modernize app for Azure with azd, deploy with azd, function app, timer trigger, service bus trigger, event-driven function, managed identity, generate Bicep, generate Terraform, create and deploy to Azure.
azure-ai
microsoft/azure-skills
Use for Azure AI: Search, Speech, OpenAI, Document Intelligence. Helps with search, vector/hybrid search, speech-to-text, text-to-speech, transcription, OCR. WHEN: AI Search, query search, vector search, hybrid search, semantic search, speech-to-text, text-to-speech, transcribe, OCR, convert text to speech.
azure-deploy
microsoft/azure-skills
Execute Azure deployments for ALREADY-PREPARED applications that have existing .azure/deployment-plan.md and infrastructure files. DO NOT use this skill when the user asks to CREATE a new application — use azure-prepare instead. This skill runs azd up, azd deploy, terraform apply, and az deployment commands with built-in error recovery. Requires .azure/deployment-plan.md from azure-prepare and validated status from azure-validate. WHEN: "run azd up", "run azd deploy", "execute deployment", "push to production", "push to cloud", "go live", "ship it", "bicep deploy", "terraform apply", "publish to Azure", "launch on Azure". DO NOT USE WHEN: "create and deploy", "build and deploy", "create a new app", "set up infrastructure", "create and deploy to Azure using Terraform" — use azure-prepare for these.
azure-validate
microsoft/azure-skills
Pre-deployment validation for Azure readiness. Run deep checks on configuration, infrastructure (Bicep or Terraform), RBAC role assignments, managed identity permissions, and prerequisites before deploying. WHEN: validate my app, check deployment readiness, run preflight checks, verify configuration, check if ready to deploy, validate azure.yaml, validate Bicep, test before deploying, troubleshoot deployment errors, validate Azure Functions, validate function app, validate serverless deployment, verify RBAC roles, check role assignments, review managed identity permissions, what-if analysis, validate Container Apps deployment.