Sign inSign up

codefuckee/mobile_portainer

By codefuckee

β€’Updated 3 months ago

provide a simple interface for mobile applications to manage Docker

Image
1

3.7K

codefuckee/mobile_portainer repository overview

⁠Mobile Portainer API

English⁠ | 中文⁠

A lightweight Docker management API service built with FastAPI⁠. It is designed to provide a simple interface for mobile applications to manage Docker containers, images, networks, and volumes. It also includes a simple Web Admin UI for managing API keys and cluster nodes.

πŸ“± Companion App: This API is designed to work with the Mobile Portainer Flutter App.
πŸ‘‰ Get the App: https://github.com/CodeFuckee/mobile_portainer_flutter⁠

⁠✨ Features

  • Docker Management:
    • Containers: List, inspect details, view logs, resource stats, start, stop, restart, kill, remove, browse files, download files.
    • Images: List, pull new images, remove, inspect details.
    • Networks: List, inspect details, create, remove.
    • Volumes: List, inspect details, create, remove, browse files.
    • System: Get Docker system info, version, real-time events stream.
  • Security:
    • Core API endpoints are protected by X-API-Key.
    • Web Admin UI is protected by Basic Auth.
  • Web Admin UI:
    • Intuitive interface to manage API Access Keys.
    • Manage Cluster Nodes information.
  • Auto Update:
    • Built-in Git auto-update service that can be configured to periodically check the remote repository and update/restart automatically.
  • System Monitoring:
    • Supports mounting the host root directory for monitoring host resource usage.
  • MCP Server:
    • Built-in MCP (Model Context Protocol) server that exposes 24 Docker management tools for AI assistants (e.g., Claude Desktop).
    • Manage containers, images, networks, volumes, and system resources directly through natural language conversations.

β πŸ› οΈ Tech Stack

  • Language: Python 3.9+
  • Web Framework: FastAPI
  • Database: SQLite (managed via SQLAlchemy ORM)
  • Docker Interaction: Docker SDK for Python
  • Deployment: Docker / Docker Compose

β πŸš€ Quick Start

⁠1. Prerequisites

Ensure your server has the following installed:

⁠2. Install & Run
⁠Option A: Build from Source (Docker Compose)

Start the service directly using Docker Compose:

# Build and start in detached mode
docker-compose up -d --build
⁠Option B: Run from Docker Hub

You can also run the pre-built image directly:

Docker CLI:

docker run -d \
  --name mobile-portainer \
  -p 8000:8000 \
  -v /var/run/docker.sock:/var/run/docker.sock \
  -v mobile_portainer_data:/app/data \
  -v /:/hostfs:ro \
  -e ADMIN_USER=admin \
  -e ADMIN_PASSWORD=password \
  --restart unless-stopped \
  codefuckee/mobile_portainer:latest

Docker Compose:

version: '3.8'
services:
  api:
    image: codefuckee/mobile_portainer:latest
    ports:
      - "8000:8000"
    environment:
      - ADMIN_USER=admin
      - ADMIN_PASSWORD=password
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - ./data:/app/data
      - /:/hostfs:ro
    restart: unless-stopped
⁠3. Access the Service

Once started, you can access the following:

β βš™οΈ Environment Variables

You can configure the service by modifying the environment section in docker-compose.yml:

Variable NameDefault ValueDescription
ADMIN_USERadminUsername for Web Admin UI
ADMIN_PASSWORD...Password for Web Admin UI
IGNORED_EVENTSexec_create,exec_start,exec_dieEvent types to ignore in Docker event stream
HOST_FILESYSTEM_ROOT/hostfsMount path of host root directory inside container

β πŸ“‚ Project Structure

.
β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ core/           # Core config, security, utils
β”‚   β”œβ”€β”€ db/             # Database models and connection
β”‚   β”œβ”€β”€ mcp/            # MCP server (Model Context Protocol) tools and entry point
β”‚   β”œβ”€β”€ routers/        # API routers (Containers, Images, WebUI, etc.)
β”‚   β”œβ”€β”€ services/       # Background services (Docker Event Listener)
β”œβ”€β”€ data/               # Data persistence directory (SQLite database)
β”œβ”€β”€ docker-compose.yml  # Docker Compose orchestration file
β”œβ”€β”€ Dockerfile          # Docker image build file
β”œβ”€β”€ main.py             # FastAPI application entry point
└── requirements.txt    # Python dependencies

β πŸ“ API Usage Example

All protected API endpoints require the X-API-Key header.

Get Container List:

GET /containers/json HTTP/1.1
Host: localhost:8000
X-API-Key: <Your-API-Key-From-Web-UI>

You can generate and manage these API Keys after logging into the Web Admin UI (/).

β πŸ”Œ MCP Server

Mobile Portainer includes a built-in MCP (Model Context Protocol)⁠ server that allows AI assistants (such as Claude Desktop, Cursor, and other MCP-compatible clients) to manage Docker resources directly through natural language conversations.

⁠How It Works

The MCP server runs as a standalone subprocess communicating via stdio. It does NOT run as part of the FastAPI HTTP service β€” instead, it is spawned directly by the AI client. The server exposes 24 Docker management tools across 5 categories:

CategoryTools
Containerslist_containers, get_container, get_container_logs, start_container, stop_container, restart_container, kill_container, pause_container, unpause_container, remove_container, run_container
Imageslist_images, get_image, pull_image, remove_image
Networkslist_networks, get_network
Volumeslist_volumes, get_volume, remove_volume
Systemget_system_info, get_system_usage, list_stacks, get_stack_containers

The get_system_info tool aggregates Docker stats, Git version info, and system resource usage into a single response. The run_container tool parses natural docker run-style commands, so you can ask "run nginx in the background" and it just works.

⁠Starting the Server
python -m app.mcp.server
⁠Claude Desktop Configuration

Add the following to your claude_desktop_config.json:

{
  "mcpServers": {
    "mobile-portainer": {
      "command": "python",
      "args": ["-m", "app.mcp.server"],
      "env": {
        "MOBILE_PORTAINER_API_KEY": "your-api-key"
      }
    }
  }
}
⁠Authentication

The MCP server checks API keys in the following priority order:

  1. Environment variable β€” If MOBILE_PORTAINER_API_KEY is set, the key must match exactly.
  2. Database fallback β€” If no environment variable is set, it looks up the key in the api_keys database table (keys managed via the Web Admin UI).
  3. No-auth mode β€” If neither is configured, all requests are allowed through.

⚠️ For production use, it's strongly recommended to set MOBILE_PORTAINER_API_KEY or manage keys via the Web Admin UI.

Tag summary

Content type

Image

Digest

sha256:f48a32ed2…

Size

117.1 MB

Last updated

3 months ago

docker pull codefuckee/mobile_portainer