Intro
Docker named volumes are the recommended way to persist data generated by and used by Docker containers. Unlike bind mounts, named volumes are managed by Docker and provide better isolation, portability, and performance. However, once containers rely on named volumes for critical data such as databases, user uploads, or configuration files, the health and capacity of those volumes become essential to application reliability. Unmonitored volumes can fill up, fail to mount, or become orphaned, leading to application errors, data loss, or downtime.
This guide provides a practical, step-by-step approach to monitoring Docker named volumes and setting up alerts. We will cover what metrics to track, how to collect them without disrupting your existing setup, how to configure alerting rules, how to build dashboards, and how to handle common incidents. By the end, you will have a repeatable process to keep your persistent data safe and your applications running smoothly.
Version and Environment Inventory
Before implementing any monitoring, you need to know what you are working with. This section covers the prerequisites and the tools we will use in this guide.
Docker Version
First, check your Docker version. The commands in this guide assume Docker Engine 20.10 or later, but most concepts apply to older versions as well.
docker version --format '{{.Server.Version}}'
Expected output example:
20.10.17
If you are using Docker Desktop on macOS or Windows, the version will be similar but may differ in patch numbers.
Host Operating System
The host OS matters because volume data is stored on the host filesystem. For this guide, we assume a Linux host, but Windows and macOS hosts with Docker Desktop can be monitored with the same tools. To check your OS:
uname -a
Example output:
Linux myhost 5.15.0-58-generic #64-Ubuntu SMP ... x86_64 GNU/Linux
Monitoring Tools
We will use the following open-source tools, which are widely adopted and easy to set up:
- Prometheus: A time-series database and monitoring system that scrapes metrics from exporters.
- Node Exporter: A Prometheus exporter for hardware and OS metrics, including filesystem usage.
- cAdvisor: A container advisor that provides container-level metrics, including volume usage; it can be run as a container or integrated with Docker.
- Grafana: A visualization platform to create dashboards and configure alerts.
- Alertmanager: A component that handles alerts from Prometheus and sends notifications to various destinations (email, Slack, etc.).
These tools can be installed directly on the host or run as containers. For production, a common pattern is to run Prometheus, Grafana, and Alertmanager as containers, with Node Exporter running on the host. cAdvisor can be run as a container with access to the Docker socket and the host's / filesystem (read-only) to collect volume metrics.
Topology Assumptions
We assume a single Docker host with multiple containers using named volumes. You can extend the approach to multiple hosts by adding more exporters and configuring Prometheus to scrape them, but the core principles remain the same.
Safe Configuration Path
In this section, we will set up monitoring and alerts for Docker named volumes in a step-by-step manner, starting with a safe, non-intrusive configuration. We will focus on filesystem usage metrics, which are the most critical for volume health, and then add alerting rules based on those metrics.
1. Collecting Volume Usage Metrics
Docker named volumes are stored under /var/lib/docker/volumes/<volume_name>/_data on the host by default. Therefore, monitoring the filesystem usage of the Docker root directory or the specific volume paths will give us the data we need. For simplicity and to cover all volumes, we can monitor the filesystem that contains /var/lib/docker using Node Exporter's node_filesystem metrics.
If your Docker data directory is on a separate filesystem (for example, mounted at /var/lib/docker), then the node_filesystem metrics will already reflect the usage of that mount point. If not, you may still see the host's root filesystem usage, which includes Docker volumes. For more granular per-volume metrics, you can use a script that runs du on each volume path and exposes the results, but that adds complexity. For this guide, we will start with overall Docker filesystem usage and then optionally extend to per-volume monitoring.
Step 1: Run Node Exporter
Run Node Exporter on the host. You can download the binary or run it via Docker. Since we want to monitor host filesystems, running it as a container with access to the host's filesystem is common, but it's often easier to install it directly. Here, we'll run it using Docker for portability, but ensure it has access to the host's filesystem.
docker run -d \
--name node-exporter \
--restart unless-stopped \
--net="host" \
--pid="host" \
-v "/:/host:ro,rslave" \
quay.io/prometheus/node-exporter:latest \
--path.rootfs=/host
This command runs Node Exporter in host network mode and mounts the host root filesystem read-only at /host inside the container, then tells the exporter to use that as root. The exporter will then expose metrics on port 9100. Verify it's running:
docker ps --filter name=node-exporter
Expected output includes the container status as Up.
Step 2: Run cAdvisor for Container-Level Metrics (Optional but Recommended)
cAdvisor provides per-container filesystem metrics, including volume usage, which can be more granular. Run it with access to the Docker socket and host filesystem:
docker run -d \
--name=cadvisor \
--restart unless-stopped \
--volume=/:/rootfs:ro \
--volume=/var/run:/var/run:ro \
--volume=/sys:/sys:ro \
--volume=/var/lib/docker/:/var/lib/docker:ro \
--volume=/dev/disk/:/dev/disk:ro \
--publish=8080:8080 \
--detach=true \
gcr.io/cadvisor/cadvisor:latest
cAdvisor will expose metrics on port 8080, including container filesystem usage. We'll use these later for more detailed alerts.
2. Setting Up Prometheus to Scrape Metrics
Now configure Prometheus to scrape both Node Exporter and cAdvisor.
Create a prometheus.yml file with the following content:
global:
scrape_interval: 15s
scrape_configs:
- job_name: 'node'
static_configs:
- targets: ['localhost:9100']
- job_name: 'cadvisor'
static_configs:
- targets: ['localhost:8080']
Run Prometheus as a container, mounting the config file:
docker run -d \
--name prometheus \
--restart unless-stopped \
-p 9090:9090 \
-v /path/to/prometheus.yml:/etc/prometheus/prometheus.yml \
prom/prometheus:latest
Replace /path/to/prometheus.yml with the actual path. Check that Prometheus is up and scraping targets by visiting http://localhost:9090/targets or using the API:
curl -s http://localhost:9090/api/v1/targets | jq '.data.activeTargets[] | {job: .labels.job, health: .health}'
Expected output:
{"job":"node","health":"up"}
{"job":"cadvisor","health":"up"}
3. Alerting Rules for Volume Usage
Now that we have metrics, we can define alerting rules. We will focus on:
- Overall Docker filesystem usage above a threshold (e.g., 80% and 90%)
- Per-volume usage above a threshold if you have cAdvisor metrics (optional)
- Alert on volume mount failures (if using Docker events or logs)
For the basics, create a Prometheus alert rule file volume_alerts.yml:
groups:
- name: docker_volumes
rules:
- alert: DockerVolumeUsageHigh
expr: (node_filesystem_avail_bytes{mountpoint="/var/lib/docker"} / node_filesystem_size_bytes{mountpoint="/var/lib/docker"}) * 100 < 20
for: 5m
labels:
severity: warning
annotations:
summary: "Docker volume filesystem is over 80% full"
description: "The filesystem containing Docker volumes ({{ $labels.mountpoint }}) has less than 20% free space. Current available: {{ $value | humanize }} bytes."
- alert: DockerVolumeUsageCritical
expr: (node_filesystem_avail_bytes{mountpoint="/var/lib/docker"} / node_filesystem_size_bytes{mountpoint="/var/lib/docker"}) * 100 < 10
for: 5m
labels:
severity: critical
annotations:
summary: "Docker volume filesystem is over 90% full"
description: "The filesystem containing Docker volumes ({{ $labels.mountpoint }}) has less than 10% free space. Immediate action required."
If your Docker data directory is not a separate mount point, you may need to adjust the mountpoint filter. Alternatively, you can monitor the root filesystem, but that will include other data and may produce false positives. If you have cAdvisor, you can create an alert per container using container filesystem metrics, but that is more advanced.
Add this rule file to Prometheus by mounting it and updating the prometheus.yml to include the rule files. Or, you can use the Prometheus web UI to create rules, but for persistence, edit the config file.
Now restart Prometheus or send a SIGHUP to reload configuration:
docker kill --signal=HUP prometheus
Verify the rules are loaded:
curl -s http://localhost:9090/api/v1/rules | jq '.data.groups[] | .name'
You should see docker_volumes in the list.
4. Setting Up Grafana Dashboards and Alerting
We will create a Grafana dashboard to visualize volume usage. Then we can either let Prometheus send alerts to Alertmanager, which then notifies via email, Slack, etc., or use Grafana's built-in alerting. For simplicity, we will use Prometheus Alertmanager.
First, run Grafana:
docker run -d \
--name grafana \
--restart unless-stopped \
-p 3000:3000 \
grafana/grafana:latest
Access Grafana at http://localhost:3000, default credentials admin/admin. Add Prometheus as a data source (Configuration -> Data Sources -> Add data source -> Prometheus). Set the URL to http://prometheus:9090 if Grafana runs in the same Docker network, or http://localhost:9090 if on the host network (adjust accordingly).
Now create a new dashboard and add a panel to show Docker volume filesystem usage. Use the following PromQL queries:
- Total size:
node_filesystem_size_bytes{mountpoint="/var/lib/docker"} - Available:
node_filesystem_avail_bytes{mountpoint="/var/lib/docker"} - Used percentage:
100 - (node_filesystem_avail_bytes{mountpoint="/var/lib/docker"} / node_filesystem_size_bytes{mountpoint="/var/lib/docker"}) * 100
Set the panel type to Stat or Graph as needed. You can also create a Gauge panel with the used percentage.
5. Configuring Alertmanager
Run Alertmanager:
docker run -d \
--name alertmanager \
--restart unless-stopped \
-p 9093:9093 \
prom/alertmanager:latest
Tell Prometheus about Alertmanager by adding the following to prometheus.yml:
alerting:
alertmanagers:
- static_configs:
- targets: ['localhost:9093']
Reload Prometheus. Now alert notifications will be sent to Alertmanager. You need to configure Alertmanager with a receiver (e.g., email, Slack). Create an alertmanager.yml file and mount it. Example for email:
global:
smtp_smarthost: 'smtp.example.com:587'
smtp_from: '[email protected]'
smtp_auth_username: 'user'
smtp_auth_password: 'password'
route:
receiver: 'email'
receivers:
- name: 'email'
email_configs:
- to: '[email protected]'
Then run Alertmanager with the config:
docker run -d \
--name alertmanager \
--restart unless-stopped \
-p 9093:9093 \
-v /path/to/alertmanager.yml:/etc/alertmanager/alertmanager.yml \
prom/alertmanager:latest
Now, when an alert fires, you'll receive an email.
6. Docker Volume Events and Logs (Optional)
While filesystem usage is the most common metric, you might also want to alert on volume-related events, such as failed mounts. Docker emits events that can be captured. For example, you can listen to Docker events and filter for volume-related ones:
docker events --filter 'type=volume'
This will show events like volume create, destroy, mount, unmount. To alert on these, you would need to forward these events to your monitoring system, perhaps via a custom script or using a log aggregation tool. This is beyond the scope of this guide, but it's good to know.
Verification and Diagnostics
After setting up monitoring, you need to verify that everything works and know how to diagnose issues.
1. Verify Data Collection
- Check Node Exporter metrics:
curl http://localhost:9100/metrics | grep node_filesystem_avail_bytes - Check cAdvisor metrics:
curl http://localhost:8080/metrics | grep container_fs_usage_bytes - Check Prometheus targets are up (as shown earlier).
- Query Prometheus for a sample metric:
curl -s 'http://localhost:9090/api/v1/query?query=node_filesystem_avail_bytes'
2. Test Alert Rules
To test the alert, you can temporarily fill a volume with data to push usage over the threshold. For example, if your Docker root is on a small test filesystem, create a large file inside a volume:
docker run --rm --mount type=volume,src=myvolume,dst=/data alpine dd if=/dev/zero of=/data/bigfile bs=1M count=1000
This will create a 1GB file in the volume, increasing usage. Check Prometheus alerts: curl -s http://localhost:9090/api/v1/alerts or view in the Prometheus UI. After the for duration (5 minutes), the alert should fire and appear in Alertmanager.
Remember to delete the test file to free space:
docker run --rm --mount type=volume,src=myvolume,dst=/data alpine rm /data/bigfile
3. Diagnose Common Issues
- No metrics from Node Exporter: Check if the container is running and the host filesystem is mounted correctly. Check logs:
docker logs node-exporter. - Prometheus cannot scrape targets: Check network connectivity and target configuration. Use
docker exec prometheus wget -qO- http://localhost:9100/metrics(if Prometheus container has wget) or check the Prometheus logs. - Alerts not firing: Check the alert rule expression in Prometheus UI -> Alerts. Look for evaluation errors.
- Alertmanager not sending notifications: Check Alertmanager logs and configuration. Visit Alertmanager UI at http://localhost:9093 to see alerts and silence status.
Failure Modes and Recovery
Even with monitoring, things can go wrong. Here are common failure modes and how to recover.
1. Volume Filesystem Full
If the volume filesystem reaches 100%, containers may fail to write data, leading to application errors. Recovery steps:
- Identify the largest volumes:
du -sh /var/lib/docker/volumes/*/_data | sort -h - Delete unnecessary data inside volumes or prune unused volumes:
docker volume prune(be careful! This removes all unused volumes). - Expand the filesystem if possible (LVM, etc.).
- Implement log rotation and cleanup jobs to prevent recurrence.
2. Volume Mount Failures
If a container cannot mount a volume, it will fail to start. Check with docker inspect <container_name> and look for errors in Mounts and Log. Common causes include missing volume, permission issues, or corrupted volume data.
Recovery: recreate the volume if empty, or restore from backup. Check filesystem permissions and ownership.
3. Monitoring System Itself Fails
If Prometheus or Node Exporter goes down, you lose visibility. Ensure monitoring components are set to restart automatically (--restart unless-stopped) and consider monitoring the monitoring (e.g., using a separate uptime check).
4. False Positives in Alerts
If you get alerts for volume usage but the volume is actually fine (e.g., the mountpoint is shared with other data), adjust the alert threshold or use a more specific metric, such as per-volume usage from cAdvisor or a custom collector.
Rollback Plan
If the monitoring setup causes problems (e.g., performance impact, too many alerts), you can easily roll back:
- Stop the monitoring containers:
docker stop node-exporter cadvisor prometheus grafana alertmanager - Remove them:
docker rm ... - Remove any configuration changes.
Since monitoring is read-only, it should not affect application data.
Common Pitfalls and How to Avoid Them
Monitoring Docker volumes seems straightforward, but several pitfalls can undermine its effectiveness. Here are the most common ones and how to steer clear of them.
1. Monitoring the Wrong Mountpoint
A frequent mistake is to monitor the root filesystem (/) instead of the specific mountpoint where Docker stores volumes. If your Docker data directory is on a separate partition (e.g., /var/lib/docker), the root filesystem metrics will not reflect volume usage, leading to missed alerts. Always verify the actual mountpoint for /var/lib/docker using df -h /var/lib/docker and use that in your alert expressions. If the directory is not a separate mount, consider monitoring the entire root filesystem but be aware of other data that may affect thresholds.
2. Alert Threshold Too Low or Too High
Setting thresholds incorrectly can cause alert fatigue or missed warnings. Too low (e.g., 70% usage) may trigger frequent non-urgent alerts, while too high (e.g., 98%) leaves little time to react. A balanced approach is to set a warning at 80% and a critical at 90% usage, with a for duration of 5-10 minutes to avoid flapping. Adjust thresholds based on your volume growth rate: if volumes fill slowly, a longer duration is acceptable.
3. Not Accounting for Ephemeral Data in Volumes
Some volumes may contain temporary or cache data that can be safely deleted. If you treat all volume data as critical, you may over-provision storage or take unnecessary recovery actions. Implement a policy to classify volumes and exclude those with ephemeral data from high-severity alerts, or create separate alert rules for them.
4. Ignoring Per-Volume Granularity
Overall filesystem usage can mask a single volume that is filling rapidly. Relying solely on aggregate metrics may delay detection. Use cAdvisor or a custom exporter to monitor per-volume usage, especially for critical volumes like databases. For example, you can use du in a cron job to export per-volume usage to Prometheus via a textfile collector.
5. Forgetting to Test Alerting End-to-End
Many teams configure alerts but never test them until a real incident occurs. This can lead to failures in notification delivery or incorrect alert content. Schedule a quarterly test where you intentionally fill a test volume to trigger an alert and verify that the notification reaches the intended recipient via the configured channel.
Operations Checklist
Use this checklist regularly (e.g., weekly or monthly) to ensure your volume monitoring remains effective. Each item includes a responsible owner (assign a specific person or role) and a suggested review frequency.
| Checklist Item | Owner (Example) | Frequency |
|---|---|---|
| Verify Prometheus targets are up (Node Exporter, cAdvisor) | DevOps Engineer: Priya Shah | Weekly |
| Check for any active alerts related to volumes | On-call engineer | Daily |
| Review volume usage trends in Grafana dashboard; look for unexpected growth | Platform Lead: Carlos Mendez | Weekly |
Inspect largest volumes using docker system df -v | System Administrator: John Lee | Monthly |
Remove unused volumes: docker volume ls -qf dangling=true then prune if safe | System Administrator: John Lee | Monthly |
| Test alerting by simulating a high-usage scenario (create and delete a large file) | QA Engineer: Emily Chen | Quarterly |
| Review alert rules and thresholds; adjust if false positives or missed issues | DevOps Engineer: Priya Shah | Monthly |
| Ensure backup and restore procedures for volumes are in place and tested | Backup Administrator: Sam Patel | Quarterly |
| Update monitoring tools to latest stable versions | DevOps Engineer: Priya Shah | Quarterly |
Conclusion
Monitoring Docker named volumes is essential for maintaining application reliability and preventing data loss. In this guide, we set up a monitoring stack using Prometheus, Node Exporter, cAdvisor, Grafana, and Alertmanager. We configured alerting rules based on filesystem usage and provided steps for verification, diagnosis, and recovery. By following the operations checklist and avoiding common pitfalls, you can keep your volume monitoring effective over time.
Next steps to consider:
- Extend monitoring to per-volume usage metrics for higher granularity.
- Add alerting on volume events (e.g., failed mounts) using Docker event logs.
- Implement automated volume cleanup and rotation policies.
- Integrate alerts with your existing notification channels (Slack, PagerDuty, etc.).
- For multi-host environments, set up Prometheus federation or use a centralized monitoring solution.
With these practices, you can ensure your Docker named volumes are well-monitored and protected.