Docker icon

Docker

Interact with Docker via Portainer API

Actions107

Overview

This node allows you to interact with Docker containers through the Portainer API, specifically enabling you to prune (clean up) unused or stopped containers on a selected Docker endpoint. Pruning containers helps free up system resources by removing containers that are no longer needed.

Common scenarios where this node is useful include:

  • Automating cleanup of stopped or exited containers in CI/CD pipelines.
  • Periodic maintenance tasks to keep Docker environments tidy.
  • Managing container lifecycle in large-scale Docker deployments via Portainer.

For example, you can configure the node to prune all containers older than a certain timestamp or those matching specific labels, helping maintain an efficient Docker environment without manual intervention.

Properties

Name Meaning
EndpointID Name or ID The identifier of the Docker endpoint managed by Portainer where the prune operation will be executed. You can select from a list of available endpoints or specify one using an expression. This determines which Docker environment the node interacts with.
Additional Fields Optional extra parameters for the prune operation. Currently supports:
- Filters: JSON-encoded filters to refine which containers to prune. Filters include:
  • until=<timestamp> — prune containers created before this time (supports Unix timestamps, date strings, or duration strings like "10m", "1h30m").
  • label — prune containers based on label presence or absence, e.g., label=key, label=key=value, label!=key, or label!=key=value.

Output

The node outputs JSON data representing the result of the prune operation. This typically includes information about how many containers were removed and any space reclaimed. The exact structure depends on the Portainer API response but generally contains:

  • Count of containers deleted.
  • Space freed by pruning.
  • Possibly details about individual containers pruned.

No binary data output is produced by this node.

Dependencies

  • Requires access to a Portainer instance with API enabled.
  • Needs an API authentication token configured as credentials in n8n to authorize requests.
  • The node uses the Portainer API endpoint /api/endpoints/{endpointId}/docker/containers/prune to perform the prune operation.
  • The user must have appropriate permissions on the Portainer endpoint to prune containers.

Troubleshooting

  • Invalid EndpointID: If the specified endpoint ID does not exist or is inaccessible, the node will fail. Ensure the endpoint is correctly selected and reachable.
  • Authentication Errors: Missing or invalid API credentials will cause authorization failures. Verify the API key/token is valid and has sufficient permissions.
  • Malformed Filters: Filters must be valid JSON strings following the expected format. Incorrect filter syntax may lead to errors or unexpected behavior.
  • API Connectivity Issues: Network problems or incorrect Portainer URL configuration can prevent the node from reaching the API. Confirm network connectivity and correct base URL setup.
  • Permission Denied: The user associated with the API token must have rights to prune containers on the target endpoint.

Links and References

Discussion