portainer_stack_update
Update or redeploy a Docker stack while preserving env vars. Supports new compose content, env changes, forced image pull, and service pruning.
Instructions
Update (redeploy) an existing stack.
The stack's stored Env variables are always preserved: Portainer replaces the whole Env list on every update, so this tool reads the current list first and merges your changes into it. Omit every optional argument to simply redeploy the stack as it is.
To pick up a newly pushed build of a :latest image, pass
pull_image=true — a plain redeploy reuses the image already on the
nodes.
Args: stack_id: The ID of the stack to update compose_content: New Docker Compose content (YAML). If omitted, the stored file is redeployed unchanged. Must not contain [REDACTED] (inspect with reveal_env=true first). env: Env variables to add or overwrite, e.g. {"TAG": "v2"} env_remove: Names of Env variables to delete prune: Remove services no longer in the compose file (Swarm only). Defaults to the stack's current setting. pull_image: Force re-pulling images before redeploying (Portainer's "Re-pull image and redeploy"; default false) detach_from_git: Required to update a git-backed stack — Portainer converts it to a plain file-based stack and drops the git link and auto-update. Refused otherwise. endpoint_id: Endpoint ID (derived from the stack itself if omitted)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| env | No | ||
| prune | No | ||
| stack_id | Yes | ||
| env_remove | No | ||
| pull_image | No | ||
| endpoint_id | No | ||
| compose_content | No | ||
| detach_from_git | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |