Portainer icon

Portainer

Trabalhe com dados da API do Portainer para gerenciar Docker

Overview

The "Stack - Update" operation in this node allows you to update an existing Docker stack managed by Portainer. This involves sending a new or modified Docker Compose file (stack file content) along with optional environment variables and a prune flag to the Portainer API, which then updates the stack accordingly.

This operation is useful when you want to modify the configuration of a running stack, such as changing service definitions, updating images, or adjusting environment variables without recreating the entire stack from scratch.

Practical examples:

  • Updating a web application stack to use a newer version of an image.
  • Adding or modifying environment variables for services within the stack.
  • Removing services that are no longer referenced in the updated stack file by enabling pruning.

Properties

Name Meaning
Environment ID The ID of the Portainer environment/endpoint where the stack is deployed.
Stack ID The unique identifier of the stack to be updated.
Stack File Content The content of the Docker Compose file or stack file describing the stack's services and config.
Environment Variables A collection of environment variables to set for the stack. Each variable has a name and value.
Prune Services Boolean flag indicating whether to prune (remove) services that are no longer referenced in the updated stack file.

Output

The output of this operation is the JSON response returned by the Portainer API after attempting to update the stack. This typically includes details about the updated stack, confirmation of the update, or error information if the update failed.

No binary data is produced by this operation.

Dependencies

  • Requires access to a Portainer instance with its API enabled.
  • Requires an API key credential configured in n8n to authenticate requests to the Portainer API.
  • The base URL of the Portainer API must be configured in the credentials.

Troubleshooting

  • Common issues:

    • Invalid or missing Environment ID or Stack ID will cause the API request to fail.
    • Malformed or invalid Docker Compose content in Stack File Content can result in errors from Portainer.
    • Insufficient permissions or incorrect API key may lead to authentication errors.
    • If Prune Services is enabled, services removed unintentionally from the compose file might be deleted.
  • Error messages:

    • Authentication errors: Check that the API key credential is correct and has sufficient permissions.
    • 404 Not Found: Verify that the specified Environment ID and Stack ID exist.
    • Validation errors on the stack file: Ensure the Docker Compose YAML syntax is valid and compatible with the Portainer version.
    • Network errors: Confirm connectivity to the Portainer API endpoint.

Links and References

Discussion