npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

portainer-stack-recreate

v1.0.1

Published

A Node.js CLI tool to recreate Portainer Docker stacks with latest images

Downloads

5

Readme

Portainer Stack Recreate

A Node.js CLI tool to recreate Portainer Docker stacks with latest images. This tool automates the process of updating and recreating containers in a Portainer stack to ensure they're running the latest images.

Features

  • 🔍 Fetch and identify Portainer stacks
  • 📋 Get stack data and configuration files
  • 🔄 Update stack configuration
  • 📦 Find all containers in a stack
  • 🚀 Recreate containers with latest images
  • 🎨 Colored console output for better UX
  • 🔒 Support for insecure HTTPS connections
  • 📝 Comprehensive error handling

Installation

Global Installation (Recommended)

npm install -g portainer-stack-recreate

Local Installation

npm install portainer-stack-recreate

From Source

git clone https://github.com/yourusername/portainer-stack-recreate.git
cd portainer-stack-recreate
npm install
npm link

Usage

Basic Usage

portainer-stack-recreate \
  --url https://your-portainer-instance.com:9443 \
  --api-key your-portainer-api-key \
  --stack-name your-stack-name

With Insecure HTTPS

If your Portainer instance uses a self-signed certificate:

portainer-stack-recreate \
  --url https://your-portainer-instance.com:9443 \
  --api-key your-portainer-api-key \
  --stack-name your-stack-name \
  --insecure

Using Short Options

portainer-stack-recreate \
  -u https://your-portainer-instance.com:9443 \
  -k your-portainer-api-key \
  -s your-stack-name

Options

| Option | Short | Required | Description | |--------|-------|----------|-------------| | --url | -u | Yes | Portainer instance URL (e.g., https://portainer.example.com:9443) | | --api-key | -k | Yes | Portainer API key | | --stack-name | -s | Yes | Name of the stack to update and recreate | | --insecure | | No | Allow insecure HTTPS connections (skip SSL verification) | | --version | -v | No | Display version information | | --help | -h | No | Display help information |

Getting Your Portainer API Key

  1. Log into your Portainer instance
  2. Go to Account SettingsAPI Keys
  3. Click Add key
  4. Give it a name and copy the generated key
  5. Use this key with the --api-key option

Examples

Recreate a Production Stack

portainer-stack-recreate \
  --url https://portainer.production.com:9443 \
  --api-key ptr_abc123def456ghi789jkl012mno345pqr678stu901vwx234yz567= \
  --stack-name production-app

Recreate a Development Stack with Self-Signed Certificate

portainer-stack-recreate \
  --url https://portainer.dev.local:9443 \
  --api-key ptr_dev_key_here \
  --stack-name dev-app \
  --insecure

Using Environment Variables

You can also use environment variables for sensitive data:

export PORTAINER_URL="https://portainer.example.com:9443"
export PORTAINER_API_KEY="ptr_your_api_key_here"

portainer-stack-recreate \
  --url "$PORTAINER_URL" \
  --api-key "$PORTAINER_API_KEY" \
  --stack-name my-app

What This Tool Does

  1. Fetches Stack List: Retrieves all stacks from your Portainer instance
  2. Finds Target Stack: Locates the specified stack by name
  3. Gets Stack Data: Retrieves the current stack configuration and environment variables
  4. Gets Stack File: Fetches the stack file (docker-compose.yml) content
  5. Updates Stack: Updates the stack with current configuration
  6. Finds Containers: Gets all containers and filters those belonging to the stack
  7. Recreates Containers: Recreates each container with PullImage=true to get latest images

Output Example

🔍 Fetching stack list from https://portainer.example.com:9443 ...
📋 Found stack: my-app (ID: 123, Endpoint: 456)
📋 Getting stack data for my-app (ID: 123)...
📄 Getting stack file for my-app (ID: 123)...
🔄 Updating stack my-app (ID: 123) on endpoint 456...
✅ Stack my-app (ID: 123) updated successfully
🔍 Getting all containers from endpoint 456...
📦 Total containers found: 15
🔍 Filtering containers for stack my-app...
📦 Found 3 containers in stack my-app
🔄 Recreating container /my-app_web_1 (ID: abc123) with PullImage=true...
✅ Container /my-app_web_1 (ID: abc123) recreated successfully
🔄 Recreating container /my-app_db_1 (ID: def456) with PullImage=true...
✅ Container /my-app_db_1 (ID: def456) recreated successfully
🔄 Recreating container /my-app_cache_1 (ID: ghi789) with PullImage=true...
✅ Container /my-app_cache_1 (ID: ghi789) recreated successfully
✅ All containers in stack my-app (ID: 123) recreated successfully with latest images

Error Handling

The tool provides detailed error messages for various scenarios:

  • Missing required options: Clear indication of what's missing
  • Invalid API key: Authentication error details
  • Stack not found: Lists available stacks
  • Network errors: Connection and timeout information
  • Container recreation failures: Specific container error details

Requirements

  • Node.js 14.0.0 or higher
  • Access to a Portainer instance
  • Valid Portainer API key
  • Network access to the Portainer API

Development

Prerequisites

  • Node.js 14.0.0+
  • npm

Setup

git clone https://github.com/yourusername/portainer-stack-recreate.git
cd portainer-stack-recreate
npm install

Running Locally

node bin/portainer-stack-recreate.js --help

Publishing to npm

npm login
npm publish

License

MIT License - see LICENSE file for details.

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

Support

If you encounter any issues or have questions:

  1. Check the Issues page
  2. Create a new issue with detailed information
  3. Include your Portainer version and Node.js version

Changelog

v1.0.1

  • Bug fixes and improvements
  • Enhanced error handling

v1.0.0

  • Initial release
  • Basic stack recreation functionality
  • Colored console output
  • Command-line argument parsing
  • Error handling and validation