Cleanup and disk space
How many releases Dockflow keeps, what leaves the server with old releases, and how dockflow prune frees the rest.
Every release keeps on the server what a rollback needs: its images and its uploaded files. After each successful run, Dockflow deletes them for the releases that left retention.
Docker objects that Dockflow does not track, such as dangling images from other tools or stopped containers, stay until you run dockflow prune.
Retention
releases.keep sets how many releases an environment keeps. The default is 10 and the minimum is 2.
version: 1
app: shop
releases:
keep: 5
environments:
production:
releases:
keep: 20
staging: {}Here staging keeps 5 releases and production 20.
A successful run is a deploy, a rollback, or a restart, stop, scale or destroy --only, which also record a release. After each one, the agent keeps:
- the newest
keepreleases that succeeded (statusactiveorsuperseded); - every release newer than the oldest of those, so failed attempts in between stay visible in
dockflow releases.
It deletes the other release records. A failed run deletes nothing.
dockflow rollback --to <seq> can restore any listed release that went live (active or superseded).
What leaves with an old release
| Object | What happens |
|---|---|
| Release record | Deleted from the server's state |
| Images | Removed from the server's Docker daemon, unless a kept release of the same environment still uses them |
| Server-local registry | The image manifests of those images are deleted. Their layers are freed by the registry's garbage collection, which runs with dockflow prune |
| Uploaded files | The upload manifests and file contents that no kept release uses are deleted from the store, including the copies of files that uploads replaced |
Containers are not part of retention. When a run succeeds, the containers of the release it replaced are removed right away. A rollback starts new containers from the kept images, so it transfers nothing.
Dockflow never deletes images from an external registry (registry.url). Use the registry's own retention policies.
dockflow prune
dockflow prune removes Docker objects that nothing needs, on the server of the environment you name. It acts on the whole server, not only on that environment's app.
dockflow prune productionWithout options, it removes stopped containers, untagged images and networks that Dockflow does not manage, and runs the server-local registry's garbage collection. With one or more of the options below, it does only those:
| Option | What it removes |
|---|---|
--containers | Stopped containers (exited, created or dead) that Dockflow does not manage |
--images | Untagged images that no container uses |
-a, --all | Every unused image, tagged ones too, instead of only untagged ones (implies --images) |
--volumes | Unused anonymous volumes that Dockflow did not create |
--networks | Unused networks that Dockflow does not manage |
--registry | The layers of the server-local registry that no kept release uses (its garbage collection) |
It prints what it removed and the space the images took:
removed 3 containers, 12 images (2.4 GiB), 0 volumes, 2 networksdockflow prune production --images -a
dockflow prune production --volumes
dockflow prune production --registryWhat prune never removes
- Containers Dockflow manages, running or stopped: services, including those stopped with
dockflow stop, the switch, the registry. - The app volumes declared in Compose files, and every volume Dockflow created.
--volumestouches only unused anonymous volumes. - The images of every release in retention, of every app on the server, and the images of the switch, the registry and the agent.
- Images that a container uses, and networks that Dockflow manages.
Registry garbage collection
Run dockflow prune (or --registry) when no deploy is in progress, for example from a scheduled job at a quiet hour. The registry's garbage collection must not run while an image is being pushed to it: a layer pushed during the collection can be deleted.
Checking disk space
dockflow diagnose checks the filesystem that holds Dockflow's state (/var/lib/dockflow). It reports a disk space problem, and exits with code 9, when that filesystem has less than 2 GiB free, or less than 5% of its size and less than 10 GiB free. Without problems, it prints the free space:
dockflow diagnose productionNo problem found: every service runs its containers (38.2 GiB free on disk).When space runs low:
- Run
dockflow pruneto remove unused images, stopped containers and registry layers. - Lower
releases.keepif each release holds large images or uploads. The next successful deploy deletes what the older releases held. - Check the space taken by uploads of large trees that change often: the store keeps the contents of every release in retention. See uploads.
To look closer, dockflow ssh production -- df -h shows the server's filesystems, and dockflow list images production -a lists every image on the server.
Operating an environment
The commands that inspect, troubleshoot and change a running environment, grouped by task.
Several apps on one server
Run several apps on one server, let them talk through shared networks, mount remote storage with Docker volume plugins, and keep one app from starving the others.