Skip to main content

Overview

Remove unused Docker images from an environment to reclaim disk space. Supports pruning dangling images (untagged) or all unused images (including tagged images not used by any container).

Endpoint

Query Parameters

env
integer
Environment ID to prune images from. Optional for local environments.
dangling
boolean
default:"true"
Prune mode:
  • true or omitted: Remove only dangling images (untagged)
  • false: Remove all unused images including tagged ones

Authentication

Requires images:remove permission for the specified environment.

Response Format

Returns job ID for progress tracking:

Result Format

The final result contains deleted images and space reclaimed:

Response Fields

ImagesDeleted
array
Array of deleted/untagged image objects:
  • Deleted: Image SHA256 that was removed
  • Untagged: Image tag that was removed
SpaceReclaimed
integer
Total disk space reclaimed in bytes

Prune Modes

Dangling Only (default)

Removes only untagged images (labeled <none>:<none>):
This is the safest option and matches Docker CLI default behavior:

All Unused Images

Removes all images not currently used by any container:
Equivalent to Docker CLI:
Pruning with dangling=false will remove all unused images including tagged ones. This can remove images you may want to keep for quick container creation.

Implementation

Docker API Integration

The prune operation uses Docker’s native prune API:
Docker API uses dangling=false to prune all unused images, which is counterintuitive. The filter specifies what to keep, not what to remove.

Usage Examples

Prune Dangling Images

Prune All Unused Images

Track Prune Progress

Automated Cleanup Script

Error Responses

403
object
Permission denied - user lacks images:remove permission
error
object
Prune operation failed

Scheduled Pruning

Dockhand supports automatic image pruning via the scheduler:
Configure auto-prune in environment settings.

Audit Logging

Prune operations are logged with full details:
Audit logs include:
  • Number of images removed
  • Space reclaimed
  • Prune mode (dangling vs all unused)
  • User who initiated the operation

Best Practices

  1. Regular Dangling Prune: Run dangling-only prune regularly (daily/weekly) to remove build artifacts
  2. Conservative All-Unused Prune: Only use dangling=false when disk space is critically low
  3. Monitor Impact: Check SpaceReclaimed to track cleanup effectiveness
  4. Automated Cleanup: Configure scheduled pruning in environment settings
  5. Pre-deployment Prune: Prune before deploying new images to ensure available space
  6. Combine with System Prune: For maximum space recovery, use system-wide prune operations

Notes

  • Prune operations only affect unused images
  • Images referenced by containers (running or stopped) are never pruned
  • Dangling images are typically intermediate build layers
  • Tagged images are only removed with dangling=false
  • Operations are atomic - either all images are pruned or none
  • Space reclaimed includes all image layers no longer referenced
  • Audit logs track all prune operations for compliance