Docker disk cleanup that knows which project each leftover came from.
CLI · web UI · single static binary · no CGO
docker system df tells you that 84 GB are gone. It cannot tell you the only
thing that matters:
This volume — which project is it from, and can I delete it without losing data?
Once a project's containers are removed, its volumes become orphans. They still
carry a com.docker.compose.project label, but nothing records where the
project lived on disk — and Docker cannot reconstruct that link afterwards.
flotsam keeps its own index of project → directory, filled passively on every
run. Months later it can still say: this 8 GB volume belonged to legacy-crm,
which lived in /home/v/work/legacy-crm, and that directory is gone.
Flotsam is what floats up after a ship goes down. That is exactly what this tool collects.
🟢 legacy-crm 12.4 GB ⚠ directory is gone
/home/v/work/legacy-crm (last seen 2025-11-03, source: index)
├─ volume legacy-crm_pgdata 8.1 GB postgresql 🟡 contains database data
├─ volume legacy-crm_uploads 3.9 GB unknown-data 🟢 project directory gone
└─ image legacy-crm-app:latest 340 MB 🟢 project directory gone
docker system prune |
flotsam | |
|---|---|---|
| Knows which project a volume came from | no | yes, even after the containers are gone |
| Checks whether the project still exists on disk | no | yes — this is the core signal |
| Tells you what is inside a volume | no | yes, read-only probe: postgres/mysql/mongo/redis/… |
| Honest reclaim estimate | no (ignores shared layers) | yes — counts layers shared only inside the deleted set |
| Selective deletion | all-or-nothing | per object, from a reviewable plan |
| Dry run | no | on by default |
Every release ships a single static binary — no runtime, no dependencies, nothing to install alongside it. All builds live on the Releases page:
| Platform | Archive |
|---|---|
| Linux x86-64 | flotsam_<version>_linux_amd64.tar.gz |
| Linux ARM64 | flotsam_<version>_linux_arm64.tar.gz |
| macOS Intel | flotsam_<version>_darwin_amd64.tar.gz |
| macOS Apple Silicon | flotsam_<version>_darwin_arm64.tar.gz |
| Windows x86-64 | flotsam_<version>_windows_amd64.zip |
| Windows ARM64 | flotsam_<version>_windows_arm64.zip |
VERSION=v0.1.0
ARCH=$(uname -m | sed 's/x86_64/amd64/;s/aarch64/arm64/')
curl -fsSL "https://github.com/vbcherepanov/flotsam/releases/download/${VERSION}/flotsam_${VERSION}_linux_${ARCH}.tar.gz" | tar xz
sudo install -m 0755 flotsam /usr/local/bin/flotsam
flotsam --versionYour user must be able to reach the Docker socket — either be in the docker
group, or run flotsam with sudo.
VERSION=v0.1.0
ARCH=$(uname -m | sed 's/x86_64/amd64/')
curl -fsSL "https://github.com/vbcherepanov/flotsam/releases/download/${VERSION}/flotsam_${VERSION}_darwin_${ARCH}.tar.gz" | tar xz
sudo install -m 0755 flotsam /usr/local/bin/flotsam
flotsam --versionIf you downloaded the archive with a browser rather than curl, macOS
quarantines it and Gatekeeper refuses to run an unsigned binary. Clear the
flag once:
xattr -d com.apple.quarantine flotsam$version = "v0.1.0"
$arch = if ($env:PROCESSOR_ARCHITECTURE -eq "ARM64") { "arm64" } else { "amd64" }
Invoke-WebRequest "https://github.com/vbcherepanov/flotsam/releases/download/$version/flotsam_${version}_windows_$arch.zip" -OutFile flotsam.zip
Expand-Archive flotsam.zip -DestinationPath "$env:LOCALAPPDATA\flotsam" -Force
& "$env:LOCALAPPDATA\flotsam\flotsam.exe" --versionAdd %LOCALAPPDATA%\flotsam to PATH (System → Environment Variables) to call
it as just flotsam. Docker Desktop with the WSL2 backend is required.
curl -fsSLO https://github.com/vbcherepanov/flotsam/releases/download/v0.1.0/checksums.txt
sha256sum -c checksums.txt --ignore-missing # macOS: shasum -a 256 -c checksums.txt --ignore-missinggo install github.com/vbcherepanov/flotsam/cmd/flotsam@latestdocker run --rm \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /:/host:ro \
-v flotsam-data:/data \
ghcr.io/vbcherepanov/flotsam:latest scanImage tags: latest, 0.1, 0.1.0, v0.1.0. Architectures: linux/amd64,
linux/arm64.
Read this before relying on the image. flotsam's central check is "does the project directory still exist on the host?". A container cannot answer that unless the host filesystem is mounted — that is what
-v /:/host:roand the image'sFLOTSAM_HOST_ROOT=/hostare for.On Linux this works. On macOS and Windows, Docker Desktop mounts the virtual machine's root for
-v /:/host, not your real disk, so your projects are invisible in there. flotsam detects this, refuses to call anything an orphan and says so in the output, instead of inviting you to delete live data. On those platforms use the native binary.
docker-compose.yml in this repository runs the web
interface:
curl -fsSLO https://raw.githubusercontent.com/vbcherepanov/flotsam/main/docker-compose.yml
curl -fsSLO https://raw.githubusercontent.com/vbcherepanov/flotsam/main/.env.example
cp .env.example .env
sed -i "s/change-me/$(openssl rand -hex 24)/" .env # macOS: sed -i ''
docker compose up -d
docker compose logs | grep http:// # the URL with the tokenThe UI is published to 127.0.0.1:7333 only. The token is fixed in .env, so
the bookmarked URL keeps working across restarts; without it every restart
would generate a new one. The flotsam-data volume keeps the project index —
that is what makes orphan detection possible later.
git clone https://github.com/vbcherepanov/flotsam.git && cd flotsam
make build # → bin/flotsam (Go 1.25+, no Node required)flotsam scan # take inventory, fill the index, delete nothing
flotsam report --orphaned # what is left of projects that no longer exist
flotsam plan --orphaned-only # build a deletion plan
flotsam apply --plan flotsam-plan-*.json # dry run (default)
flotsam apply --plan flotsam-plan-*.json --no-dry-run # actually deleteRun flotsam scan regularly (cron, launchd). Every run teaches the index one
more project→directory pair while the containers still exist — that is what
makes orphan detection possible months later.
flotsam webStarts a local server on 127.0.0.1:7333, prints a URL with a one-time token
and opens the browser. Everything the CLI does, in the browser: inventory,
volume probing, plan building, dry run and real deletion — with the same
guarantees. Bilingual (English / Russian), light and dark themes, an
explanation panel on every page.
| Command | What it does |
|---|---|
flotsam scan |
Take inventory, update the index. --refresh-sizes, --scan-fs, --roots, --probe |
flotsam report |
Grouped tree. --group-by project|type|risk, --risk, --min-size, --orphaned, --explain, --sort |
flotsam projects |
Flat project list: path, whether it exists, size, activity |
flotsam plan |
Build a deletion plan. --risk, --project, --kind, --orphaned-only, --older-than, --min-size, -o |
flotsam apply |
Apply a plan. --plan, --yes, --no-dry-run, --object, --force-risky, --continue-on-error |
flotsam inspect volume <name> |
Volume card: project, path, size, contents, mount history, verdict |
flotsam host |
Why the freed space did not appear on disk, and what to do about it |
flotsam index list|set|forget|prune |
Manage the index. index set repairs the link of an orphaned volume by hand |
flotsam web |
Web UI. --addr, --token, --no-open, --allow-remote |
Global flags: --config, --json, --no-color, --docker-host, --host-root, -v/-vv, -q.
Exit codes: 0 success · 1 error · 2 bad arguments · 3 daemon unreachable ·
4 plan applied partially.
| Level | Meaning | |
|---|---|---|
| 🟢 | safe |
Project directory is gone, dangling image, empty volume, long-stopped container |
| 🟡 | probably-safe |
Project dormant > 30 days, recent unused image, recent build cache |
| 🔴 | risky |
Volume holds database data, project is active, unknown origin, ambiguous path |
| ⛔ | never |
Protected by config, volume attached to a container, image of a running container |
risky and never never enter a plan, whatever flags you pass. A red
object can only be removed one at a time, and only after you type its full name:
flotsam apply --object legacy_uploads --force-risky --no-dry-runapplyis a dry run by default; real deletion needs--no-dry-run.neverobjects are never deleted.- A volume with
RefCount > 0is never deleted, not even with--force-risky. - The inventory is re-collected immediately before deleting; anything that changed meanwhile is skipped with a warning.
- No
docker system prune -a— only targeted deletions by ID. - The probe mounts a volume read-only and never pulls an image silently.
- flotsam never modifies anything outside Docker: not your project
directories, not the VM disk images.
flotsam hostprints commands; you run them. - Every operation is appended to
~/.local/share/flotsam/history.jsonl. - The web UI listens on
127.0.0.1only, requires the token from the printed URL, validatesHostandOrigin(DNS-rebinding protection) and passes the token in a custom header — no cookies, so CSRF is impossible. - A directory counts as "gone" only when its parent directory is visible, so an unmounted subtree is never mistaken for a deleted project.
~/.config/flotsam/config.yaml (Windows: %APPDATA%\flotsam\config.yaml).
See config.example.yaml. Every threshold is configurable:
thresholds:
stale_container_days: 30
dormant_project_days: 30
active_project_days: 7
stale_buildcache_days: 14
volume_size_cache_ttl: 24h
protected: # gets the "never" verdict; no flag overrides it
projects: ["prod-*"]
volumes: ["*_pgdata", "*_mysql"]
images: ["myregistry.local/*"]On macOS and Windows, Docker lives in a VM whose disk is one big file that never
shrinks by itself. After apply you get two numbers:
Freed inside Docker: 22 GB
Freed on the host disk: 0 B ⚠ see `flotsam host`
flotsam host finds Docker.raw (macOS) or ext4.vhdx (WSL2), shows apparent
vs allocated size and prints the exact commands to compact it. It never runs
them for you.
Docker daemon ──▶ dockerapi ──▶ inventory ──▶ classify ──▶ plan ──▶ execute
│ │ │
index ◀─────── resolve config
(project→path) (label → index → FS scan)
- index — SQLite (pure Go, no CGO), filled passively from container labels.
- resolve — turns a project name into a directory: live label → index → filesystem scan → unknown.
- layers — builds the layer graph and answers "how much is actually freed" for a whole set rather than per row (99.4 % of images matched exactly on the development host — see DECISIONS.md).
- classify — 18 ordered rules; the first match wins.
internal/dockerapi exposes a narrow interface, so everything above it is
tested against fixtures without Docker. An integration test
(make test-integration) creates a real compose project, deletes its directory
and verifies the full cycle against a live daemon.
make build # binary (CGO_ENABLED=0)
make ui # rebuild the web UI (Node 20+) into web/dist
make ui-dev # Vite dev server against a running `flotsam web`
make test # unit tests
make test-integration # tests against a live daemon
make lint # go vet + gofmt
make dist # release archives + checksums for 6 platforms
make docker # local imageThe built SPA is committed to web/dist, so go build needs no Node; CI fails
if the committed bundle drifts from the sources.
Contributions are welcome — please keep the safety guarantees above intact and add a test for any rule you touch.
MIT © Vitalii Cherepanov