The dashboard was working yesterday. Today the database keeps restarting, an image update fails halfway through, and Docker says no space left on device.
Somewhere in the search results, somebody suggests a prune command with every available flag. That is a good moment to slow down. The server may contain months of monitoring history, a password vault, or the only copy of an application configuration.
A full disk needs a short investigation before it needs a cleanup command. This guide walks through that investigation on a Linux home server: identify the full filesystem, find the growing data, recover enough space to operate, and put a limit on whatever caused the problem.
The quick answer: check both space and inodes, compare host usage with Docker’s inventory, and reclaim only data you have identified. Container logs, application data and build cache need different fixes.
df -hT
df -i
docker system df -v
docker ps -a --size
These commands inspect the situation. If Docker is unavailable, start with the two df commands and go to the emergency headroom section. Avoid volume pruning and manual deletion inside Docker’s storage directories.
Scope: a standalone Linux Docker Engine host with Docker Compose v2, using Bash and GNU tools as found on Ubuntu/Debian. Run host commands on the machine where the Docker daemon stores its data. Docker Desktop, Kubernetes, Swarm and storage-pool repair need their own procedures. Numerical examples below are illustrative, not measurements from a particular homelab.
1. Find the filesystem that is actually full
Start with df -hT and df -i. The first shows filesystem capacity, type and mount point. The second checks inode use: a filesystem can run out of entries for new files while still having free bytes.
Read the mount points carefully. Free space on /mnt/media will not help a full root filesystem if Docker lives under /var. A nearly empty system disk will not help an application whose data volume is full.
| What you see | What to investigate next |
|---|---|
| Little or no available space on Docker’s filesystem | Logs, image layers, build cache and container writable layers. |
| Inode use near 100%, but bytes remain | Large numbers of small files in caches, sessions, queues or application data. |
| An application data mount is full | That application’s retention and storage, even if Docker’s own directory is small. |
| Host capacity looks healthy | The exact error path, quotas, a full tmpfs such as /dev/shm, or filesystem/pool-specific limits. |
Record which Docker installation you are looking at:
docker context show
docker version
docker compose version
docker info --format 'Host={{.Name}} Root={{.DockerRootDir}} Logging={{.LoggingDriver}}'
docker info --format '{{json .DriverStatus}}'
A remote Docker context can point at another machine. Running df on your laptop while inspecting a remote daemon produces two unrelated pictures. If you use rootless Docker, keep using its normal account and context; blindly adding sudo to Docker commands may select a different daemon.
When Docker responds, check its reported data directory directly:
DOCKER_ROOT="$(docker info --format '{{.DockerRootDir}}')"
if [ -n "$DOCKER_ROOT" ] && [ -d "$DOCKER_ROOT" ]; then
df -hT -- "$DOCKER_ROOT"
df -i -- "$DOCKER_ROOT"
findmnt -T "$DOCKER_ROOT"
fi
The directory test assumes you are on the daemon’s host and can access that path. An empty result or inaccessible directory is a reason to check the connection and permissions, not to guess a path.
2. Map Docker storage and application data
docker system df -v gives an inventory of Docker-managed objects. docker ps -a --size helps identify large container writable layers. Keep both views, but do not treat either as a complete accounting of the host.
Docker’s container-size figures exclude log-driver files and mounted data. Images also share layers, so adding every displayed image size can overstate the space used. See Docker’s disk-usage reference and container-size explanation.
Check the application’s mounts
# Replace this with the exact name shown by docker ps -a.
APP_CONTAINER='uptime-kuma'
docker inspect --format '{{range .Mounts}}{{printf "%s\t%s\t%s\n" .Type .Source .Destination}}{{end}}' "$APP_CONTAINER"
The columns are mount type, host source and container destination. A bind mount might point at /srv/docker/uptime-kuma/data, while a named volume has a Docker-managed source. Check the filesystem behind the real source path:
# Use the actual host Source path from the previous command.
APP_DATA='/srv/docker/uptime-kuma/data'
df -hT -- "$APP_DATA"
df -i -- "$APP_DATA"
findmnt -T "$APP_DATA"
For NFS or another remote volume, investigate the backing server and mount health too. An unavailable backup disk can also leave a normal directory at the expected mount point; a job may then write onto the root filesystem. Check findmnt before trusting a familiar folder name.
Check the storage backend
Fresh Docker Engine 29 installations use the containerd image store by default; upgraded installations can retain the older backend. With the containerd store, image and snapshot data can live separately from Docker’s data directory. Moving Docker’s data-root does not automatically move that storage. See the containerd image-store documentation.
Check the actual configuration and relevant filesystems. Do not change storage backends during cleanup or assume that everything is inside /var/lib/docker/overlay2.
For a broad, read-only directory inventory on the affected disk:
# Run one at a time; each scan may take a while.
sudo du -xhd1 /var
sudo du -xhd1 /srv
sudo du -xhd1 "$DOCKER_ROOT"
Use only paths that exist on your server. The -x option stays on one filesystem; scan separately mounted data paths separately. Start at one level, then inspect the largest relevant directory. These scans can create noticeable I/O on older disks.
Reading directory sizes is useful. Deleting Docker’s layer or snapshot directories by hand is not a supported cleanup method.
3. Recover headroom when the host is struggling
If the disk is completely full, Docker may be unable to start, remove an object or recreate a container. Pause scheduled builds, downloads and other avoidable writers. Stop a runaway service through its normal application or Compose controls where possible; allow a database enough time for its documented shutdown procedure.
First look for clearly disposable host data on the same filesystem. On an Ubuntu/Debian host, inspect the downloaded package cache:
df -hT /var/cache/apt/archives
sudo du -sh /var/cache/apt/archives
If that cache is significant and you do not need those downloaded packages for offline recovery, this removes cached package archives, without uninstalling installed packages:
sudo apt-get clean
That behaviour is documented in apt-get’s manual. An already empty cache will free nothing.
Another candidate is the system journal:
sudo journalctl --disk-usage
This next command deletes older journal history. Preserve logs needed for troubleshooting or incident investigation first. If the journal is consuming space on the affected filesystem and 200 MB is an acceptable temporary history budget:
sudo journalctl --rotate --vacuum-size=200M
Vacuuming removes archived journals; rotation makes current journal files eligible. The target does not cap every log on the machine, and rotation can fail on a completely full disk. The journalctl manual explains the options.
Recheck df after each action. If there is no known disposable data, increasing the affected filesystem’s capacity can be safer than deleting unfamiliar files. A larger VM virtual disk still needs the appropriate partition/LVM/filesystem expansion inside the guest; follow the procedure for that storage layout.
For a systemd-managed, rootful Docker daemon, inspect its state after gaining headroom:
sudo systemctl status docker --no-pager
sudo journalctl -u docker -n 60 --no-pager
If the daemon is stopped, start it after addressing the storage problem. Avoid restarting a working daemon just to see what happens. Repeated I/O errors or a read-only filesystem call for storage-health investigation before further cleanup.
4. Fix growing container logs
A service stuck in a retry loop can produce a large log while its container writable layer looks tiny. Check the selected container’s logging configuration and a short sample:
docker inspect --format '{{.Name}} {{json .HostConfig.LogConfig}}' "$APP_CONTAINER"
docker logs --tail 80 --timestamps "$APP_CONTAINER"
Look for repeated authentication failures, unreachable upstreams, debug output or a failed dependency. Rotation controls retained history; the application error still needs fixing.
On a local Linux Engine host, this checks the allocated size of the current log file and its containing directory when Docker exposes a file path:
LOG_PATH="$(docker inspect --format '{{.LogPath}}' "$APP_CONTAINER")"
if [ -n "$LOG_PATH" ] && sudo test -f "$LOG_PATH"; then
sudo du -h -- "$LOG_PATH"
sudo du -sh -- "$(dirname -- "$LOG_PATH")"
fi
The directory total includes rotated files and some container metadata. An empty path can be normal for a different logging driver. Read log content through docker logs; do not edit, truncate or remove Docker’s active log files. Docker explicitly warns against external manipulation of json-file log storage.
Add a limit to the Compose service
For a small standalone homelab, the local logging driver is a reasonable option with rotation built in. Merge this fragment into your existing service, using its actual service name. It is not a complete replacement Compose file:
services:
uptime-kuma:
# Keep this service's existing image, mounts and other settings.
logging:
driver: "local"
options:
max-size: "10m"
max-file: "3"
This gives the service a modest retained-log budget. It does not limit files written by the application into a volume or bind mount. If your existing log collector requires the JSON format, keep driver: "json-file" and configure both size and file-count limits instead.
Recreate deliberately, then verify
Logging settings belong to the container created with them. Editing a Compose file, restarting a container, or changing the daemon default does not retrofit the existing container. Docker documents the need to recreate containers for new logging settings.
Before recreating anything:
- Identify every persistent mount and preserve valuable writable-layer data.
- Have an application-consistent backup on a different filesystem. A live database-directory copy is not automatically a usable backup.
- Keep the original Compose project name, files, environment and volume names.
- Check that the configured image still resolves to the intended existing version or digest.
- Allow enough headroom and schedule the service interruption.
The Docker backup guide helps inventory what needs protecting. Confirm the backup method against your application’s requirements before proceeding.
# Run from this stack's existing directory, with its usual -f/-p
# options if you use them. Keep the same project and volume names.
docker compose config --quiet
docker compose ps -a
For an existing service named uptime-kuma, recreate only that service:
# Service downtime: run only after the checks above.
docker compose up -d --no-deps --force-recreate --no-build --pull never uptime-kuma
docker compose ps -a
docker compose logs --tail 60 uptime-kuma
--no-build and --pull never avoid a build or registry pull during recovery; they do not pin an image or undo a locally changed tag. Dependencies must already be available. Recreating replaces the writable layer and old container logs. Keep mounted data and the project identity intact; do not add --renew-anon-volumes or use down -v. See Compose up’s documented behaviour.
docker compose ps -q uptime-kuma | while IFS= read -r container_id; do
docker inspect --format '{{.Name}} {{json .HostConfig.LogConfig}}' "$container_id"
done
Confirm that the output contains the intended driver and limits. Then open the application and check its existing records. A recreated container with an empty new data volume can look perfectly healthy.
If recreation fails, inspect the specific error and available space. Do not delete the data volume to make the service start. Restore the previous Compose settings if necessary; previously removed writable-layer data requires its backup.
5. Review build cache and unused images
When the inventory points to build cache, target that category. After confirming you can rebuild without the old cache, this prompts before removing eligible older cache from the daemon’s builder:
docker builder prune --filter 'until=168h'
168h is seven days. It is a review policy, not a guarantee that the cache is unimportant. Later builds may take longer or need downloads. See builder prune.
If you use Buildx with a separate builder, inspect it first:
docker buildx ls
docker buildx du
Check the builder’s name, endpoint and usage. The following is an alternative for that selected Buildx builder, which may be remote:
docker buildx prune --filter 'until=168h'
Do not run both cleanup paths automatically. Choose the builder that owns the cache you identified. The Buildx usage and prune references describe their scope.
For images, review dangling candidates and references:
docker image ls --filter dangling=true
docker system df -v
If those untagged, unused images are no longer needed—including for local recovery—the narrower image cleanup is:
docker image prune
Read the confirmation prompt. Omit -a unless you have separately reviewed all images without container references. An image retained for rollback may still matter even when Docker calls it unused. Pulling a replacement also needs free space. Check the image prune reference before broadening the cleanup.
Understand what broader cleanup can remove
| Command or flag | Reason to review it carefully |
|---|---|
docker system prune | Includes stopped containers and their writable layers, alongside unused networks, dangling images and build cache. |
docker system prune -a | Expands image removal to images without container references, including possible rollback images. |
docker system prune --volumes | Also prunes eligible anonymous volumes. Anonymous does not mean empty or unimportant. |
docker volume prune -a | Can remove unused named volumes as well as anonymous ones. |
docker compose down -v | Can remove the project’s declared named volumes and attached anonymous volumes. |
These are descriptions, not a sequence to run. The current system prune, volume prune and Compose down references explain the precise scopes. “Unused” describes Docker’s references, not the value of your data.
6. Handle volumes and application data carefully
If most space belongs to a database, uploads, recordings or monitoring history, image cleanup may achieve very little. Inspect the volume and all containers that refer to it:
# Replace this with the exact volume name from your inventory.
DATA_VOLUME='homelab_app_data'
docker volume inspect "$DATA_VOLUME"
docker ps -a --filter "volume=$DATA_VOLUME" \
--format 'table {{.Names}}\t{{.Status}}\t{{.Mounts}}'
No container references does not prove that a volume is disposable. It could belong to a temporarily removed stack or contain the data needed to restore it.
Use the application’s supported retention or cleanup controls. Reducing recording retention is different from deleting database files. Database compaction and maintenance can themselves require significant temporary space; verify the application’s documented procedure before running them on a full disk.
For data worth keeping, expand storage or make a planned migration with a verified backup. Do not move live database directories between disks and hope the running container follows them.
A large writable layer also deserves attention. If important files were written outside a mount, preserve them before removing or recreating that container. Correct the storage layout after recovery. Docker’s volume documentation explains persistent storage, and the backup restore drill provides the next step: proving that the saved data can bring the service back.
7. Investigate inodes and missing space
Free gigabytes, but no room for new files
When df -i reports inode exhaustion, look for directories containing huge numbers of small files:
# Replace /srv with the affected directory/filesystem.
sudo du --inodes -x -d 1 /srv
Follow the largest counts one directory level at a time. GNU du’s inode mode helps locate them. Then use the owning application’s retention or cleanup mechanism. Random deletion from a mail queue, database directory or Docker layer store can turn a capacity problem into lost data.
You deleted a file, but the space did not return
A process may still have a deleted file open. If lsof is already installed:
sudo lsof +L1
The +L1 option selects open files whose directory links have been removed. Examine the process, file type, size and affected device. Do not add every displayed row as though it were a unique file.
Arrange a supported reload or graceful restart of the owning service so it closes the file. Do not kill an unfamiliar process or write through its /proc file descriptor. If Docker itself owns the handle, any required daemon maintenance affects more than one application.
Other df/du mismatches can involve snapshots, reserved blocks, permissions or files hidden beneath mount points. When bytes and inodes both look healthy, investigate quotas and the actual filesystem or storage pool. Do not start deleting snapshots or changing reserved-space settings without identifying their purpose.
8. Verify recovery before calling it fixed
Run the host checks again, then inspect the affected stack from its normal project directory:
df -hT
df -i
docker system df
docker compose ps -a
docker compose logs --since 10m --tail 100
Check more than the container’s running state:
- The intended filesystem has usable headroom and available inodes.
- The application opens and its existing records, uploads or history are present.
- An ordinary application operation succeeds without new storage errors.
- The intended data mount is attached; a new empty directory has not taken its place.
- The corrected logging or retention policy is actually active.
- A later measurement shows that usage is stable or growing at the expected rate.
If a database experienced failed writes or an abrupt shutdown, follow its own recovery and integrity-check guidance. A green dashboard alone does not establish that every write survived.
For illustration, a root filesystem that rises from 300 MB free to 8 GB free has regained working room. That is still temporary relief if a retry loop adds 2 GB every hour. Record the cause as well as the reclaimed space.
9. Prevent the next disk-full incident
Start with the setting that failed, then make the storage layout easier to understand.
- Set retained-log limits for every service. Review verbose/debug modes, too. Put per-service settings in Compose so they travel with the stack.
- Bound application retention. Logs, recordings, downloads, monitoring history and backups each need their own budget.
- Monitor each real data filesystem. Include the Docker store, any separate containerd store, application mounts and backup destinations.
- Monitor bytes and inodes. Add a free-space floor in GB as well as a percentage. Tune alerts to disk size, write rate and how quickly you can respond.
- Leave room for maintenance. Image extraction, upgrades, restores and database work can need temporary capacity.
- Review build cache intentionally. Avoid unattended broad pruning that erases rollback assets or forgotten data.
- Test alert delivery. A monitoring service on the same full filesystem can fail alongside the application. Use an independent check for important services.
For a small host, warning at 80% and escalating at 90% can be an initial experiment, not a universal standard. A fast-growing filesystem may need an earlier alert. Measure how much time remains at the current growth rate and choose thresholds that leave time to act.
The Uptime Kuma monitoring guide covers service availability. Pair that with a host-level disk and inode check; an HTTP response does not tell you whether the filesystem is nearly full.
For new deployments, carry the logging policy into the Docker Compose starter stack. Keep exposure, permissions and mounts understandable using the Docker security guide.
10. Try a small log-rotation lab
This optional exercise compares two finite logging runs. It demonstrates retention without filling a disk. Run it in a disposable Linux Docker VM with working storage and at least 1 GB free, after resolving any real incident. It does not test database recovery or guarantee behaviour during an actual out-of-space event.
Both containers write the same 10,000 lines. One keeps the complete JSON log; the other rotates at a small size. They publish no ports and mount no host data. The container names below must be unused.
Fetch the example image and record its resolved digest alongside your Engine version:
docker pull alpine:3.22
docker image inspect --format '{{json .RepoDigests}}' alpine:3.22
alpine:3.22 is the example tag, not a claim that it is the newest release. Save the digest if you need to reproduce the same image later.
for policy in unrotated rotated; do
limit='-1'
if [ "$policy" = 'rotated' ]; then limit='32k'; fi
docker run -d --name "itrs-log-$policy" \
--network none --read-only --memory 64m --pids-limit 64 \
--log-driver json-file \
--log-opt "max-size=$limit" --log-opt max-file=2 \
alpine:3.22 sh -c '
i=0
while [ "$i" -lt 10000 ]; do
printf "line=%05d %0100d\n" "$i" 0
i=$((i + 1))
done
'
docker wait "itrs-log-$policy"
done
Each docker wait should print exit status 0. A failed run needs investigation before comparing results.
for policy in unrotated rotated; do
name="itrs-log-$policy"
docker inspect --format '{{.Name}} {{json .HostConfig.LogConfig}}' "$name"
log_path="$(docker inspect --format '{{.LogPath}}' "$name")"
if [ -n "$log_path" ] && sudo test -f "$log_path"; then
sudo du -sh -- "$(dirname -- "$log_path")"
fi
docker logs --tail 2 "$name"
done
The rotated container should retain less log history while still showing the final lines. The directory totals include metadata and filesystem allocation, so do not expect an exact 64 KB result. The current file’s size alone does not account for all rotated files.
| Record | Unrotated container | Rotated container |
|---|---|---|
| Engine version and image digest | Record your environment | Same environment |
| Container exit status | Record observed value | Record observed value |
| Container log-directory allocation | Record observed size | Record observed size |
| Final log line present | Check line 09999 | Check line 09999 |
This is a blank lab worksheet. It contains no claimed test results. Keep your observations with the server’s maintenance notes.
When you have finished, remove only the two stopped test containers. This deletes their test logs and writable layers; the downloaded image remains:
docker rm itrs-log-unrotated itrs-log-rotated
Common questions
Will docker system prune delete my database?
It depends where the database lives and which options you use. A stopped container’s writable layer can be removed by ordinary system pruning. Volume-removal options create additional risks. Inspect the mounts and backups first; the word “database” has no special protection in a cleanup command.
Why does Docker report less usage than df?
df measures a filesystem, which may also contain host logs, package caches and application bind mounts. Docker’s inventory has a different scope. Deleted-open files, filesystem overhead and snapshots can add further differences. Compare the same host and filesystem before drawing conclusions.
Can I delete files from overlay2 or containerd snapshots?
Do not use direct filesystem deletion as routine Docker cleanup. Those directories contain storage managed by Docker and containerd. Identify the owning objects and use the appropriate management tools, or make a planned storage migration.
Will restarting a container apply new log limits?
No. Recreate it with the new logging settings, preserving its persistent data and project identity, then inspect the resulting configuration.
Keep a short incident record
Write down the affected mount, available bytes and inodes, the largest contributor, the action taken and the application check that passed afterwards. Include the later reading that showed the growth had stopped.
That small record makes the next investigation quicker. It also tells you whether this server needs a larger disk, a retention change, or a fix for a service that keeps printing the same error all night.
After recovery, run the restore drill while the server is healthy. Recovery is a much better time to discover missing backup files than the next outage.
Comments
Post a Comment