Portainer icon

Portainer

Trabalhe com dados da API do Portainer para gerenciar Docker

Overview

This node integrates with the Portainer API to manage Docker stacks. Specifically, the Update Stack operation allows users to update an existing Docker stack by providing new stack file content (typically a docker-compose.yml or similar stack definition), environment variables, and an option to prune services that are no longer referenced.

Common scenarios where this node is beneficial include:

  • Automating updates to Docker Compose stacks in a Portainer-managed environment.
  • Dynamically changing environment variables for running stacks.
  • Cleaning up unused services during stack updates by pruning them.

Practical example:

  • You have a Docker Compose stack deployed via Portainer and want to update the service definitions or environment variables without manually logging into Portainer's UI. This node lets you programmatically push those changes.

Properties

Name Meaning
Environment ID The ID of the Portainer environment/endpoint where the stack resides.
Stack ID The unique identifier of the stack to update.
Stack File Content The full content of the stack file (e.g., docker-compose.yml) defining the stack services.
Environment Variables A collection of environment variables to set for the stack. Each has a Name and a Value.
Prune Services Boolean flag indicating whether to remove services that are no longer referenced in the stack.

Output

The node outputs the JSON response from the Portainer API after attempting to update the stack. This typically includes details about the updated stack or confirmation of the update action.

No binary data output is produced by this operation.

Dependencies

  • Requires a valid connection to a Portainer instance via its API.
  • An API key credential for authenticating requests to Portainer must be configured in n8n.
  • The base URL of the Portainer API endpoint must be set in the credentials.

Troubleshooting

  • Invalid Environment or Stack ID: If the provided environment or stack ID does not exist or is incorrect, the API will return an error. Verify IDs before running the node.
  • Malformed Stack File Content: Providing invalid YAML or improperly formatted stack files may cause the update to fail. Ensure the stack file content is valid and compatible with Docker Compose specifications.
  • Insufficient Permissions: The API key used must have permissions to update stacks in the specified environment.
  • Network Issues: Connectivity problems to the Portainer API endpoint will result in request failures. Check network access and API availability.
  • Prune Option Side Effects: Enabling pruning removes services no longer referenced; use with caution to avoid unintended service deletions.

Links and References

Discussion