Implement persistent storage with Docker volumes, bind mounts, and backup strategies
Manages Docker persistent storage with named volumes, bind mounts, and tmpfs. Use when containers need data persistence, file sharing, or temporary storage. Includes backup/restore commands and permission fixes.
/plugin marketplace add pluginagentmarketplace/custom-plugin-docker/plugin install pluginagentmarketplace-docker-container-assistant@pluginagentmarketplace/custom-plugin-dockerThis skill inherits all available tools. When active, it can use any tool Claude has access to.
assets/config.yamlassets/schema.jsonassets/volume-config.yamlreferences/GUIDE.mdreferences/PATTERNS.mdscripts/validate.pyMaster Docker persistent storage including named volumes, bind mounts, tmpfs, and data backup/restore procedures.
Implement reliable data persistence for containers with proper volume management, backup strategies, and permission handling.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| volume_name | string | No | - | Name for the volume |
| mount_type | enum | No | volume | volume/bind/tmpfs |
| backup | boolean | No | false | Include backup commands |
| Type | Persistence | Use Case | Managed By |
|---|---|---|---|
| Named Volume | Yes | Production data | Docker |
| Bind Mount | Yes | Development, configs | Host |
| tmpfs | No (memory) | Secrets, temp files | Docker |
| Anonymous | Container lifetime | Scratch space | Docker |
# Create volume
docker volume create app_data
# Use in container
docker run -d \
-v app_data:/var/lib/postgresql/data \
postgres:16-alpine
# Inspect volume
docker volume inspect app_data
# List volumes
docker volume ls
# Remove unused volumes
docker volume prune
# Development - mount source code
docker run -d \
-v $(pwd)/src:/app/src \
node:20-alpine
# Read-only config
docker run -d \
-v /etc/app/config.yaml:/app/config.yaml:ro \
myapp
# Sensitive data in memory
docker run -d \
--tmpfs /app/secrets:rw,noexec,nosuid,size=64m \
myapp
# Compose syntax
services:
app:
volumes:
- type: tmpfs
target: /app/tmp
tmpfs:
size: 100m
services:
database:
image: postgres:16-alpine
volumes:
- db_data:/var/lib/postgresql/data
- ./init.sql:/docker-entrypoint-initdb.d/init.sql:ro
environment:
POSTGRES_PASSWORD: ${DB_PASSWORD}
app:
image: myapp
volumes:
- uploads:/app/uploads
- ./config:/app/config:ro
volumes:
db_data:
driver: local
uploads:
external: true # Pre-created
# Backup to tar file
docker run --rm \
-v app_data:/source:ro \
-v $(pwd)/backups:/backup \
alpine tar cvf /backup/app_data_$(date +%Y%m%d).tar -C /source .
# Compressed backup
docker run --rm \
-v app_data:/source:ro \
-v $(pwd)/backups:/backup \
alpine tar czvf /backup/app_data_$(date +%Y%m%d).tar.gz -C /source .
# Restore from tar
docker run --rm \
-v app_data:/dest \
-v $(pwd)/backups:/backup:ro \
alpine tar xvf /backup/app_data_20240101.tar -C /dest
docker run --rm \
-v source_volume:/from:ro \
-v target_volume:/to \
alpine cp -av /from/. /to/
| Error | Cause | Solution |
|---|---|---|
volume in use | Container running | Stop container first |
permission denied | UID mismatch | Fix ownership |
no space left | Disk full | Clean up or expand |
path not found | Bind mount missing | Create directory |
# Check ownership
docker run --rm -v app_data:/data alpine ls -la /data
# Fix ownership (match container user)
docker run --rm -v app_data:/data alpine chown -R 1000:1000 /data
# SELinux (RHEL/CentOS)
docker run -v /host/path:/container/path:Z myimage
docker volume lsdocker exec <c> df -hls -la in container# Check volume location
docker volume inspect app_data --format '{{.Mountpoint}}'
# Check container mounts
docker inspect <container> --format '{{json .Mounts}}'
# Check disk usage
docker system df -v
Skill("docker-volumes")
This skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
This skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.
This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.