Docker/Portainer PowerShell Module
A PowerShell Module Using Docker/Portainer Web API to manage container
Introduction
The Docker/Portainer PowerShell module is a comprehensive toolkit designed to simplify the management and automation of Docker containers and Portainer stacks. With this module, developers and system administrators can seamlessly interact with Docker and Portainer through PowerShell, providing an efficient way to manage services, monitor status, and automate container operations.
Description
This module bridges the gap between PowerShell scripting and Docker/Portainer environments. It includes a wide range of functions that allow users to perform tasks such as starting/stopping containers and stacks, retrieving status information, and interacting with the Portainer API. By leveraging this module, you can streamline your workflows, ensure consistency in your operations, and enhance your control over Dockerized environments.
Goal
The primary goal of this module is to provide a simple yet powerful interface for managing Docker containers and Portainer stacks, enabling:
- Automation of repetitive tasks.
- Monitoring of container and stack statuses.
- Integration of Docker/Portainer operations into existing PowerShell scripts and pipelines.
Functions
Below is a description of each function included in the module:
Stack Management
-
Get-StackStatusString
Retrieves a user-friendly string describing the status of a Portainer stack. -
Start-FirefoxStack
Starts the Firefox stack defined in the Portainer instance. -
Get-FirefoxStackStatus
Fetches the current status of the Firefox stack in Portainer. -
Convert-PortainerStacks
Converts stack definitions or formats for compatibility with Portainer. -
Get-PortainerStacks
Retrieves a list of all stacks managed by the Portainer server. -
Stop-PortainerStack
Stops a specific stack running in Portainer. -
Start-PortainerStack
Starts a specific stack in Portainer.
Docker Compose Management
Get-DockerComposeFile
Fetches the Docker Compose file used by a specific Portainer stack.
Portainer API Utilities
-
Get-PortainerAuthenticationHeader
Generates an authentication header for interacting with the Portainer API. -
Get-PortainerServerAndPort
Retrieves the server address and port of the Portainer instance. -
Test-PortainerApi
Tests the connection to the Portainer API to ensure it is reachable and authenticated.
Service-Specific Utilities
Restart-Plex
Restarts the Plex Media Server container through Docker.
Docker Container Management
-
Get-DockerContainers
Retrieves a list of all Docker containers on the server. -
Convert-ContainerData
Converts raw container data into a structured format for easy processing. -
Get-DockerContainersData
Fetches detailed data about Docker containers, including status and configuration. -
Restart-DockerContainer
Restarts a specific Docker container. -
Stop-DockerContainer
Stops a running Docker container. -
Start-DockerContainer
Starts a stopped Docker container. -
Get-DockerContainerStatus
Retrieves the current status of a specific Docker container.
How to Use
-
Clone or download this module to your local machine.
-
Build the module in PowerShell (PowerShell.ModuleBuilder module)
git clone https://github.com/arsscriptum/PowerShell.Module.Docker.git cd PowerShell.Module.Docker make
- Use the provided functions to interact with Docker and Portainer.
Prerequisites
- Docker installed and running on the host system.
- Portainer instance accessible via API.
- PowerShell version 7.0 or higher.
- PowerShell.ModuleBuilder module
Repository
Source is located in the PowerShell.Module.Docker github repository.