Docker icon

Docker

Interact with Docker via Portainer API

Overview

This node allows users to interact with Docker through the Portainer API, specifically focusing on managing Docker images. The "Image Prune" operation enables pruning (removing) unused Docker images from a specified Docker endpoint managed by Portainer. This is useful for cleaning up disk space by deleting images that are no longer needed or used.

Common scenarios include:

  • Automatically cleaning up dangling or unused Docker images in CI/CD pipelines.
  • Managing Docker host storage by removing old or untagged images.
  • Applying filters to prune images selectively based on labels, creation time, or usage status.

Example: A user can configure this node to prune all dangling images older than 24 hours on a specific Docker endpoint, helping maintain a clean and efficient Docker environment.

Properties

Name Meaning
EndpointID Name or ID Selects the Docker endpoint (host) where the prune operation will be executed. You can choose from a list of available endpoints or specify an ID directly using an expression.
Additional Fields Optional collection of extra parameters to customize the prune operation.
└─ Filters JSON-encoded string specifying filters to apply when pruning images. Available filters include:
- dangling=<boolean>: If true, prune only unused and untagged images; if false, prune all unused images.
- until=<string>: Prune images created before this timestamp (supports Unix timestamps, date strings, or duration strings like 10m, 1h30m).
- label: Filter images by label presence or absence, e.g., label=key, label=key=value, label!=key.

Output

The node outputs JSON data representing the result of the prune operation as returned by the Portainer API. This typically includes details such as the amount of space reclaimed and lists of deleted images.

No binary data output is involved.

Dependencies

  • Requires access to a Portainer instance with the Docker endpoints configured.
  • Needs an API key credential for authenticating with the Portainer API.
  • The node uses the Portainer API endpoint /api/endpoints/{endpointId}/docker to perform Docker operations.
  • The user must have appropriate permissions on the selected Docker endpoint to prune images.

Troubleshooting

  • Common issues:

    • Invalid or missing endpoint ID: Ensure the selected endpoint exists and is accessible.
    • Authentication failures: Verify the API key credential is valid and has sufficient permissions.
    • Incorrect filter syntax: Filters must be valid JSON strings and follow the expected format; otherwise, the API may reject the request.
    • Network connectivity problems between n8n and the Portainer server.
  • Error messages:

    • HTTP 401 Unauthorized: Check API credentials and permissions.
    • HTTP 404 Not Found: The specified endpoint ID does not exist.
    • HTTP 400 Bad Request: Likely caused by malformed filters or invalid query parameters.

Resolving these usually involves verifying configuration settings, credentials, and ensuring the Portainer API is reachable.

Links and References

Discussion