Skip to main content

A Python package for automating Docker and Portainer installation

Project description

py-docker-admin

PyPI version License: GPL v3

A Python package for automating Docker and Portainer installation and stack deployment.

Features

  • ✅ Install Docker on Debian-based systems
  • ✅ Install Portainer CE as a Docker container with auto-restart policy
  • ✅ Create admin user in Portainer via API
  • ✅ Deploy Docker stacks from compose files
  • ✅ YAML configuration with Pydantic validation
  • ✅ Command-line interface with Typer
  • ✅ Comprehensive error handling
  • ✅ Rich logging with color output
  • Automatic startup: Portainer container starts automatically on system boot
  • Reverse proxy support: Configure base URL for Portainer behind reverse proxy

Installation

Recommended: Install via pipx (for end users)

# Install using pipx (recommended for CLI usage)
pipx install py-docker-admin

# Or install using pip
pip install py-docker-admin

Development Installation

# Clone the repository from GitLab
git clone https://gitlab.com/grenzfall/py-docker-admin.git
cd py-docker-admin

# Install using uv (recommended)
uv add .

# Or install using pip in development mode
pip install -e .

Usage

Basic Usage

# Run with default configuration
py-docker-admin

# Or use the short alias
pda

# Use a configuration file
py-docker-admin --config my_config.yaml

# Override admin credentials
py-docker-admin --username admin --password mypassword

# Enable verbose logging
py-docker-admin --verbose

Configuration

Create a YAML configuration file (see example_config.yaml):

docker:
  install: true
  restart_service: true
  add_user_to_group: true

portainer:
  container_name: portainer
  port: 9000
  admin_username: admin
  admin_password: securepassword123
  volume: /var/run/docker.sock:/var/run/docker.sock
  remove_existing: false
  # base_url: /portainer  # Uncomment for reverse proxy support

stacks:
  - name: myapp
    compose_file: ./docker-compose.yml
    env_file: ./docker-compose.env

Reverse Proxy Support

For running Portainer behind a reverse proxy (e.g., Nginx, Apache), use the base_url option:

portainer:
  base_url: /portainer  # Portainer will be accessible at http://your-domain.com/portainer

The base_url must start with a forward slash (e.g., /portainer, /docker-admin). When configured, Portainer container will be started with the --base-url parameter, ensuring proper path handling behind reverse proxies.

Requirements

  • Python 3.12+
  • Debian-based Linux system (for Docker installation)
  • Docker (will be installed if not present)
  • sudo privileges (for Docker installation)

Development

Setup

# Create virtual environment
uv venv

# Activate environment
source .venv/bin/activate

# Install development dependencies
uv add pytest ruff

Running Tests

pytest tests/

Code Style

# Run Ruff linter
ruff check src/

# Format code
ruff format src/

Architecture

py_docker_admin/
├── cli.py                # Command-line interface
├── models.py             # Configuration models
├── docker.py             # Docker installation
├── portainer.py          # Portainer installation & API
├── stack.py              # Stack deployment
├── utils.py              # Utility functions
└── exceptions.py         # Custom exceptions

License

GNU General Public License v3.0 (GPL-3.0)

This project is licensed under the GNU General Public License version 3.0. See the LICENSE file for the full license text.

Copyright © 2026 GreenQuark greenquark@gmx.de

Contributing

Contributions are welcome! Please open an issue or submit a merge request on our GitLab repository.

Support

For issues and questions, please use the GitLab issue tracker.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py_docker_admin-0.4.7.tar.gz (112.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py_docker_admin-0.4.7-py3-none-any.whl (41.5 kB view details)

Uploaded Python 3

File details

Details for the file py_docker_admin-0.4.7.tar.gz.

File metadata

  • Download URL: py_docker_admin-0.4.7.tar.gz
  • Upload date:
  • Size: 112.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for py_docker_admin-0.4.7.tar.gz
Algorithm Hash digest
SHA256 6d1243dca00850de868654fec1276ed2aad184dbe59b7f44bce35de9d72d4746
MD5 2d03100382d23d78b6e5552b32022baf
BLAKE2b-256 4b7732e86eaa33f42a02e020703a83e9c56b16f95799b28d1bb8528a0c0cac6c

See more details on using hashes here.

File details

Details for the file py_docker_admin-0.4.7-py3-none-any.whl.

File metadata

File hashes

Hashes for py_docker_admin-0.4.7-py3-none-any.whl
Algorithm Hash digest
SHA256 3ff1f26f0f27bb83df4fc64b4c44b91784b587012a931eff241972bfdd828753
MD5 e82337c6e722bb5fa62d1415a6131411
BLAKE2b-256 e0bf8a676dc4b8d56c32a1a6b833ab0ec7a6e101a83d43318e60e836544c25e5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page