Commit 7fef0b6
committed
daemon/volume: don't print warnings for non-volume directories
When restoring volumes at startup, the local volume driver's constructor
([daemon/volume/local.New]) iterates over all directories found inside the
volume storage path (`/var/lib/docker/volumes`). It does not (currently) check
for presence of other indicators that the directory is an actual volume, such
as the `_data` directory being present, or a `opts.json`.
In situations where `/var/lib/docker/volumes` contains directories that were
not created by docker, this can result in errors when calculating the size
of volumes (`docker system df`);
Before (re)starting the daemon, create some directories;
mkdir /var/lib/docker/volumes/notavolume
echo "some file" > /var/lib/docker/volumes/notavolume/some-file
mkdir /var/lib/docker/volumes/notavolume2
Then, start the daemon, and run `docker system df`. The daemon logs will
now contain warnings about the path not being found:
WARN[2026-02-09T11:27:31.940713593Z] Failed to determine size of volume error="lstat /var/lib/docker/volumes/notavolume/_data: no such file or directory" volume=notavolume
WARN[2026-02-09T11:27:31.940765468Z] Failed to determine size of volume error="lstat /var/lib/docker/volumes/notavolume2/_data: no such file or directory" volume=notavolume2
The [calcSize] function used to calculate the size of a volume already ignores
files _within_ the volume's storage that are not / no longer found, but does
not ignore errors if the base directory (`_data`) itself doesn't exist.
This patch:
- makes the logs ignore "not found" errors
- adds a TODO to look into ignoring these directories during daemon startup
(when instantiating the driver and restoring volumes).
[daemon/volume/local.New]: https://github.com/moby/moby/blob/6c5233e1098dc689b2e665087780695ac8864e95/daemon/volume/local/local.go#L51-L85
[calcSize]: https://github.com/moby/moby/blob/daeaac0d3cf147cc7450a3ab9a869327c71bad45/daemon/internal/directory/directory_unix.go#L13-L24
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>1 parent d94c62f commit 7fef0b6
2 files changed
+9
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
| 76 | + | |
76 | 77 | | |
77 | 78 | | |
78 | 79 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
| 7 | + | |
6 | 8 | | |
7 | 9 | | |
8 | 10 | | |
| |||
69 | 71 | | |
70 | 72 | | |
71 | 73 | | |
72 | | - | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
73 | 80 | | |
74 | 81 | | |
75 | 82 | | |
| |||
0 commit comments