Docker icon

Docker

Interact with Docker via Portainer API

Actions107

Overview

This node allows users to interact with Docker through the Portainer API, specifically focusing on managing Docker images. The "Build Prune" operation is designed to clean up and prune build cache data related to Docker images on a specified endpoint. This helps free disk space by removing unused or old build cache layers.

Common scenarios for this node include:

  • Automating cleanup of Docker build caches to maintain optimal disk usage.
  • Integrating Docker image maintenance into CI/CD pipelines.
  • Managing multiple Docker endpoints via Portainer in a centralized workflow.

For example, a user might schedule this node to run periodically to prune build caches older than a certain date or to ensure that a minimum amount of free disk space is maintained on the Docker host.

Properties

Name Meaning
EndpointID Name or ID Selects the Docker endpoint (via Portainer) where the build prune operation will be executed. Users can choose from a list of available endpoints or specify an ID using an expression.
Additional Fields A collection of optional parameters to customize the prune operation:
- Keep Storage (Deprecated) Amount of disk space in bytes to keep for cache. Replaced by "Reserved Space".
- Reserved Space Amount of disk space in bytes to reserve for cache storage, preventing pruning below this threshold.
- Max Used Space Maximum allowed disk space in bytes for cache storage.
- Min Free Space Target amount of free disk space in bytes to achieve after pruning.
- All Boolean flag indicating whether to remove all types of build cache. Defaults to true.
- Filters JSON encoded string representing filters to apply when pruning. Filters can specify criteria such as cache age (until), specific IDs, types, descriptions, and usage flags (inuse, shared, private). This allows fine-grained control over which build cache objects are pruned.

Output

The node outputs JSON data representing the result of the build prune operation. This typically includes information about the amount of space reclaimed and details about the pruned cache items.

If the node supports binary data output, it would relate to any files or artifacts returned by the API, but based on the provided code and properties, the primary output is JSON summarizing the prune results.

Dependencies

  • Requires access to a Portainer instance with the Docker environment managed via Portainer API.
  • Needs an API key credential or token configured in n8n to authenticate requests to the Portainer API.
  • The node depends on the Portainer API's /api/endpoints/{endpointId}/docker/build/prune endpoint.
  • The node dynamically loads available Docker endpoints from Portainer to populate the "EndpointID" property.

Troubleshooting

  • Invalid Endpoint ID: If the selected endpoint does not exist or is unreachable, the node will fail. Verify the endpoint ID and network connectivity to the Portainer server.
  • Authentication Errors: Ensure the API key or authentication token is valid and has sufficient permissions to perform Docker operations via Portainer.
  • Incorrect Filter Format: The "Filters" field expects a JSON encoded string. Malformed JSON or unsupported filter keys may cause errors. Validate JSON syntax before execution.
  • Deprecated Parameter Warning: Using the "Keep Storage" parameter will work but is deprecated; switch to "Reserved Space" to avoid future issues.
  • Disk Space Parameters Misconfiguration: Setting conflicting values for reserved space, max used space, and min free space could lead to unexpected pruning behavior. Review these settings carefully.

Links and References

Discussion