Skip to main content

๐Ÿ› ๏ธ Simple and interactive CLI for Docker container management

Project description

Docker Tool

Docker Python MIT License

Smart Docker container management with an elegant CLI

Features โ€ข Installation โ€ข Quick Start โ€ข Documentation โ€ข Contributing


Features

Core Features

  • Interactive Wizard Mode: Beautiful TUI for container management
  • Smart Container Search: Find containers by ID, name, or partial match
  • Rich Output: Colorful tables and formatted output with rich
  • Intelligent Commands: Short commands that do what you expect
  • Docker API Integration: Direct Docker SDK usage for better performance
  • Smart Error Handling: User-friendly error messages and suggestions

Advanced Features

  • Container Status Indicators: Visual status in wizard mode
  • Auto-Detection: Automatically detects Docker/Docker Compose
  • Shell Completion: Tab completion for commands (bash, zsh, fish)
  • Regex Filtering: Advanced container filtering with regex support

Installation

Prerequisites

  • Python 3.8+
  • Docker installed and running
  • pip package manager

Install from PyPI

pip install docker-tool

Install from Source

# Clone the repository
git clone https://github.com/julestblt/docker-wrapper.git
cd docker-wrapper

# Install in development mode
pip install -e .

Enable Shell Completion

# Bash
dtool --install-completion bash

# Zsh
dtool --install-completion zsh

# Fish
dtool --install-completion fish

Quick Start

Interactive Wizard Mode

The easiest way to manage containers:

# Launch the interactive wizard
dtool wizard

Features:

  • Visual container selection with status indicators
  • Context-aware actions based on container state
  • Beautiful prompts with questionary
  • Navigate with arrow keys, select with Enter

List Containers

# List running containers
dtool ps

# List all containers (including stopped)
dtool ps -a

# Interactive mode - select and manage containers
dtool ps -i

# Filter containers by name/ID
dtool ps nginx
dtool ps e5d

# Use regex filtering
dtool ps "^web-.*" -r

Documentation

Container Management Commands

Shell Access

# Quick shell access (auto-detects bash/sh)
dtool shell nginx
dtool shell backend
dtool shell e5d  # Partial ID works!

# Use specific shell
dtool shell alpine /bin/sh
dtool shell ubuntu /bin/zsh

Execute Commands

# Run single commands
dtool exec nginx "ls -la"
dtool exec backend cat /etc/hosts
dtool exec web "ps aux | grep node"

View Logs

# View last 100 lines (default)
dtool logs nginx

# Follow logs in real-time
dtool logs backend -f
dtool logs backend --follow

# View specific number of lines
dtool logs app --tail 50

Container Lifecycle

# Start containers
dtool start nginx
dtool start backend frontend db  # Multiple containers

# Stop containers
dtool stop nginx
dtool stop backend --force  # Force stop

# Restart containers
dtool restart nginx
dtool restart backend --force

# Remove containers
dtool rm old-container
dtool rm test-app --force  # Force remove running container

Smart Container Search

The tool intelligently searches for containers in this order:

  1. Exact ID match: Full container ID
  2. ID prefix: Beginning of container ID
  3. Exact name: Full container name
  4. Partial match: Grep-like search in names
# Examples
dtool shell e5d4a2b1          # ID prefix
dtool shell nginx              # Exact name
dtool shell backend            # Matches: my-backend, backend-api, etc.
dtool logs "web|api" -r        # Regex: matches web OR api

Advanced Usage

Filter and Manage

# List only Redis containers
dtool ps redis

# Stop all containers matching pattern
dtool ps "test-" -r | xargs -I {} dtool stop {}

# View logs of all API containers
dtool ps "api" | xargs -I {} dtool logs {} --tail 20

Error Handling Examples

The tool provides helpful error messages:

$ dtool shell nonexistent
โ•ญโ”€ Container Error โ”€โ•ฎ
โ”‚ Container not found! โ”‚
โ”‚                      โ”‚
โ”‚ No container with    โ”‚
โ”‚ name or ID           โ”‚
โ”‚ 'nonexistent' was    โ”‚
โ”‚ found.               โ”‚
โ”‚                      โ”‚
โ”‚ Try running:         โ”‚
โ”‚ โ€ข dtool ps -a        โ”‚
โ”‚ โ€ข dtool ps           โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

Project Structure

docker-tool/
โ”œโ”€โ”€ docker_tool/
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ cli.py           # Main CLI entry point
โ”‚   โ”œโ”€โ”€ docker_client.py # Docker SDK wrapper
โ”‚   โ”œโ”€โ”€ wizard.py        # Interactive wizard mode
โ”‚   โ”œโ”€โ”€ utils.py         # Utility functions
โ”‚   โ””โ”€โ”€ version.py       # Version information
โ”œโ”€โ”€ requirements.txt     # Python dependencies
โ”œโ”€โ”€ setup.py            # Package configuration
โ””โ”€โ”€ README.md           # This file

Why Docker Tool?

Feature Docker CLI Docker Tool
Open shell docker exec -it nginx /bin/bash dtool shell nginx
View logs docker logs -f --tail 100 nginx dtool logs nginx -f
Stop container docker stop nginx dtool stop nginx
Interactive mode Not available dtool wizard
Smart search Exact ID/name required Partial match, regex
Error messages Technical errors User-friendly guidance

Development

Setup Development Environment

# Clone the repo
git clone https://github.com/yourusername/docker-tool.git
cd docker-tool

# Create virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install in development mode
pip install -e .

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Code Style

This project uses automated code quality tools:

  • Pre-commit hooks: Automatically run on every commit
  • Black: Code formatting (line length: 88 characters)
  • Flake8: PEP8 compliance and code quality
  • Pytest: Automated testing before commits

Development Setup

# Install with development dependencies and hooks
make dev-install

# Manual pre-commit hooks setup (if needed)
pre-commit install

# Run all quality checks
make check

# Run pre-commit hooks manually
make hooks

Code Standards

  • Follow PEP 8 (enforced by flake8)
  • Use type hints where possible
  • Add docstrings to public functions
  • Maintain test coverage above 50%
  • All commits must pass pre-commit hooks

See HOOKS.md for detailed information about pre-commit hooks.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • Built with Typer - The amazing CLI framework
  • Styled with Rich - Beautiful terminal formatting
  • Interactive mode powered by Questionary
  • Docker SDK for Python

Made with love by developers who hate long Docker commands

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

docker_tool-1.0.4.tar.gz (19.6 kB view details)

Uploaded Source

Built Distribution

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

docker_tool-1.0.4-py3-none-any.whl (13.5 kB view details)

Uploaded Python 3

File details

Details for the file docker_tool-1.0.4.tar.gz.

File metadata

  • Download URL: docker_tool-1.0.4.tar.gz
  • Upload date:
  • Size: 19.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.13

File hashes

Hashes for docker_tool-1.0.4.tar.gz
Algorithm Hash digest
SHA256 6241ead906683d312c9938b21f335b288061ceed71134867716f4395b366a9c2
MD5 19b828eda643d22d4a30f9f889d7b774
BLAKE2b-256 cb408a48dc3525f1ab25441c2abceaba4e5e874eb03778c2ca64af490c48f923

See more details on using hashes here.

File details

Details for the file docker_tool-1.0.4-py3-none-any.whl.

File metadata

  • Download URL: docker_tool-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 13.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.13

File hashes

Hashes for docker_tool-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 e17025d95e42193304f3dae2c068d8d711879a6f87ed9eef82ee49e654009967
MD5 d28994d7c85a2709e96513edeab9bc25
BLAKE2b-256 3e104eece5d44517e8131947bc0e322572e2eda0d520a9ca66179de619b70e56

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