Web control panel with container support
| __pycache__ | ||
| data | ||
| static | ||
| systemd | ||
| __main__.py | ||
| auth.py | ||
| config.json | ||
| control_panel.py | ||
| database.py | ||
| README.md | ||
| requirements.txt | ||
| setup.sh | ||
Docker Control Panel - Complete Project Structure
Project Directory Layout
docker-control-panel/
├── main.py # Main entry point
├── control_panel.py # Core panel functionality
├── requirements.txt # Python dependencies
├── config.json # Configuration file (optional)
├── setup.sh # Setup script
├── systemd/
│ └── docker-panel.service # Systemd service file
├── logs/ # Log directory
└── README.md # Documentation
requirements.txt
flask==2.3.2
docker==6.1.3
gunicorn==21.2.0
python-dotenv==1.0.0
config.json (optional)
{
"REGISTRY": "your-registry.com",
"BIND_ADDRESS": "0.0.0.0:5000",
"WORKERS": "4",
"LOG_LEVEL": "INFO",
"BASE_DIR": "/mycontainers",
"SSL_ENABLED": false
}
setup.sh - Initial Setup Script
#!/bin/bash
# Docker Control Panel Setup Script
set -e
echo "Setting up Docker Control Panel..."
# Check if running as root
if [ "$EUID" -ne 0 ]; then
echo "Please run as root (sudo)"
exit 1
fi
# Install Python dependencies
echo "Installing Python dependencies..."
pip3 install -r requirements.txt
# Create necessary directories
echo "Creating directories..."
mkdir -p /mycontainers
mkdir -p logs
# Set permissions
chmod +x main.py
chmod +x control_panel.py
# Install systemd service (optional)
if [ -f "systemd/docker-panel.service" ]; then
echo "Installing systemd service..."
cp systemd/docker-panel.service /etc/systemd/system/
systemctl daemon-reload
echo "Service installed. To start: systemctl start docker-panel"
fi
echo "Setup complete!"
echo "To run in development: sudo python3 main.py"
echo "To run in production: sudo python3 main.py --production"
systemd/docker-panel.service
[Unit]
Description=Docker Control Panel
After=network.target docker.service nginx.service
[Service]
Type=simple
User=root
WorkingDirectory=/opt/docker-control-panel
Environment="REGISTRY=your-registry.com"
ExecStart=/usr/bin/python3 /opt/docker-control-panel/main.py --production
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
.env file (alternative to config.json)
REGISTRY=your-registry.com
BIND_ADDRESS=0.0.0.0:5000
WORKERS=4
LOG_LEVEL=INFO
FLASK_SECRET_KEY=your-secret-key-here
Usage Examples
1. Web Interface Mode (Development)
sudo python3 main.py
# Access at http://localhost:5000
2. Web Interface Mode (Production)
sudo python3 main.py --production
# Uses Gunicorn with multiple workers
3. CLI Mode - List Services
sudo python3 main.py --mode cli list
4. CLI Mode - Deploy Service
sudo python3 main.py --mode cli deploy myapp example.com 8080 --container-port 3000
5. CLI Mode - Manage Services
# Restart service
sudo python3 main.py --mode cli restart myapp
# Update service (pull latest image)
sudo python3 main.py --mode cli update myapp
# Remove service
sudo python3 main.py --mode cli remove myapp
6. Run as System Service
# Install service
sudo cp systemd/docker-panel.service /etc/systemd/system/
sudo systemctl daemon-reload
# Start service
sudo systemctl start docker-panel
sudo systemctl enable docker-panel # Auto-start on boot
# Check status
sudo systemctl status docker-panel
# View logs
sudo journalctl -u docker-panel -f
Environment Variables
The application supports these environment variables:
REGISTRY: Docker registry URLBIND_ADDRESS: Address to bind web server (default: 0.0.0.0:5000)WORKERS: Number of Gunicorn workers in production modeLOG_LEVEL: Logging level (DEBUG, INFO, WARNING, ERROR)BASE_DIR: Base directory for containers (default: /mycontainers)
Security Considerations
- Always run behind a reverse proxy in production (nginx with SSL)
- Add authentication before exposing to internet
- Use environment variables for sensitive data
- Regular backups of /mycontainers and configurations
- Monitor logs for suspicious activity
Next Steps for Extension
-
Add Authentication:
from flask_login import LoginManager, login_required -
Add Database:
from flask_sqlalchemy import SQLAlchemy -
Add API Endpoints:
from flask_restful import Api, Resource -
Add Background Tasks:
from celery import Celery