Skip to content

feat: optionally remove old Dokploy images on web server update - #34

Merged
agentHits merged 3 commits into
AgentHits-Devfrom
feat/dokploy-image-cleanup
Oct 7, 2026
Merged

agentHits merged 3 commits into
AgentHits-Devfrom
feat/dokploy-image-cleanup

Conversation

@agentHits

@agentHits agentHits commented Oct 7, 2026 •

Copy link
Copy Markdown
Collaborator

What

The Web Server Update dialog gets a new switch: Remove old Dokploy images, keep the last [3|4|5].

Every web server update pulls a new ~4.4 GB image, and old ones were never removed. With the switch on, only the newest N Dokploy images stay on the host.

How

  • The choice is sent with settings.updateServer({ keepImages }) and stored on the dokploy service as DOKPLOY_KEEP_IMAGES (0 = off). It survives restarts and later manual docker service update runs.
  • The cleanup runs when the new Dokploy container starts (server.ts). It can't run from the update request itself, because the update replaces the container that issued it (stop-first).
  • getDokployImageCleanupCommand(keep):
    • lists images of the fork repo (taken from the update image) and dokploy/dokploy, sorts them by creation time, keeps the newest N;
    • for each older image, removes exited/created containers of the dokploy swarm service that pin it (swarm keeps up to 5 task containers);
    • removes the image tags, then the image. Nothing is forced, so images used by running or unrelated containers stay.
  • New settings.getDokployImageKeepCount (admin) so the dialog shows the saved value. Until it loads, the update leaves the setting unchanged.

Image list and preview

Under the switch, a button (HardDrive icon) shows how many Dokploy images are on the host and their total size, e.g. 3 images · 13.36 GB. The popover lists each image, newest first, with:

  • fork version, build date and official version;
  • size, plus how much deleting it frees (unique size from docker system df -v);
  • Running now / Keep / Delete / In use, for the chosen keep count. Rows to delete are red and struck through, with the stopped task containers that go with them.

A pending update is shown as a New build row and counts as one of the kept images, because the cleanup runs after it. A footer sums what gets deleted ("Deletes 1 image, frees about 4.11 GB"). The data comes from the new admin query settings.getDokployImages; the marking is a pure client function (planDokployImageCleanup) that mirrors the shell script.

Checks

  • vitest __test__/settings/: 86 passed (incl. dokploy-image-plan.test.ts and image list parsing) (new dokploy-image-cleanup.test.ts plus router cases for passing, rejecting and turning off the keep count).
  • tsc --noEmit in apps/dokploy and packages/server; biome clean.
  • Ran the generated script against a local Docker (containerd store) with 6 throwaway images: kept the newest 3, removed one with two tags and one pinned by an exited dokploy task container, left one used by a foreign container alone.
  • Read-only dry run on dev (Docker 29.4.1, overlay2): image selection and pinned task containers found correctly; sort, awk, tail, docker exist in the Dokploy image.
  • getDokployImages run live against local Docker (6 test images, multi-tag, exited task and foreign containers, image without Env); output formats checked read-only on dev.
  • The popover was rendered in a browser on a temporary page with dev-shaped data (keep 3 → oldest red, keep 4 → nothing to delete). The whole update dialog with a real backend was not opened.

🤖 Generated with Claude Code

agentHits and others added 3 commits October 7, 2026 06:39
The update dialog gets a switch "Remove old Dokploy images, keep the
last N" (N = 3, 4 or 5). The choice is stored on the dokploy service as
DOKPLOY_KEEP_IMAGES, so it survives restarts and later manual updates.

Cleanup runs when the new Dokploy container starts, because the update
replaces the container that started it (stop-first). It removes exited
dokploy task containers that pin old images, then the images beyond
the newest N of the fork and official repositories. Nothing is forced:
images used by running or foreign containers are left alone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A button under the cleanup switch shows how many Dokploy images are on
the host and their total size. Its popover lists each image with fork
version, build date, size and the space deleting it frees, and marks
which ones stay and which ones are deleted for the chosen keep count.
A pending update counts as the newest image. Images used by other
containers are shown as kept.

settings.getDokployImages reads the images, their unique sizes from
`docker system df -v` and the containers that use them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
settings.getDokployImageKeepCount and settings.getDokployImages only
read Docker state, so they are "read" procedures.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@agentHits
agentHits merged commit 7eac0c4 into AgentHits-Dev Oct 7, 2026
8 checks passed
@agentHits
agentHits deleted the feat/dokploy-image-cleanup branch October 7, 2026 11:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant