Docker icon

Docker

Interact with Docker via Portainer API

Actions107

Overview

This node interacts with Docker through the Portainer API, specifically focusing on network management. The "Network Prune" operation allows users to remove unused Docker networks based on specified filters. This is useful for cleaning up dangling or obsolete networks to free resources and maintain a tidy Docker environment.

Practical examples include:

  • Automatically pruning networks older than a certain timestamp.
  • Removing networks that match or do not match specific labels.
  • Scheduled cleanup tasks in CI/CD pipelines or server maintenance workflows.

Properties

Name Meaning
EndpointID Name or ID Selects the Docker endpoint to target via Portainer API. You can choose from a list of available endpoints or specify an ID using an expression.
Additional Fields Optional collection of extra parameters.
└─ Filters JSON-encoded filters to refine which networks to prune. Supported filters include:
- until=<timestamp>: prune networks created before this time (supports Unix timestamps, date strings, or Go duration strings).
- label filters: prune networks with or without specific labels, 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 which networks were removed and any relevant metadata returned by the Portainer API. There is no binary output.

Dependencies

  • Requires access to a Portainer instance with Docker endpoints configured.
  • Needs an API key credential for authenticating requests to the Portainer API.
  • The node uses the Portainer API endpoint /api/endpoints/{endpointId}/docker/network/prune under the hood.
  • Proper configuration of the endpoint ID is necessary to target the correct Docker environment.

Troubleshooting

  • Common issues:

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

    • Unauthorized or 401 errors indicate authentication issues; check API credentials.
    • 404 errors may mean the endpoint ID does not exist or the URL is incorrect.
    • Malformed filter errors suggest invalid JSON or unsupported filter keys/values.

Resolving these usually involves verifying credentials, endpoint configurations, and filter formats.

Links and References

Discussion