Kratos (named after the Greek personification of strength and power) is a Python-based script for managing Docker containers and stacks via the Portainer API. This tool provides robust features to streamline container orchestration and stack management.
- Authenticate: Securely authenticate with the Portainer API.
- Container Management: Start containers and fetch logs effortlessly.
- Stack Creation: Deploy new stacks using Docker Compose content.
- Stack Insights: Retrieve detailed information about stacks and their containers.
- Notification System Integration: Notify users with container logs via external systems.
- Python 3.x
requests
library
Install dependencies with:
pip install requests
-
Configuration: Update the placeholders in the script:
PORTAINER_URL
: The URL of your Portainer instance.USERNAME
: Your Portainer username.PASSWORD
: Your Portainer password.ENDPOINT_ID
: The ID of the Portainer endpoint to target.
-
Run the script:
python kratos.py
-
Authenticate: Retrieve a JWT token to interact with the Portainer API.
-
View Stacks: Get details of all available stacks in the Portainer instance.
-
Container Logs: Fetch logs for containers and send them as notifications.
-
Create New Stack: Deploy a new stack directly from a Docker Compose file.
services:
web:
image: nginx:latest
ports:
- "1212:80"
Enable debug mode by setting DEBUG = True
in the script. This will print JWT tokens, logs, and other useful information for troubleshooting.
Enhance the script by integrating with the dynamic-notification-system. Example payload:
payload = {
"notification_type": "ntfy",
"message": {
"title": subject,
"message": message,
},
}
requests.post("http://localhost:8080/notify", data=json.dumps(payload))
Contributions are welcome! Feel free to submit issues or pull requests to improve the script.
Kratos is licensed under the MIT License.