A comprehensive Docker container management bot for Discord, developed by Catalog.fi.
Garden Guardian is a powerful Discord bot designed to simplify Docker container management through Discord's interface. This bot allows authorized users to monitor, control, and troubleshoot Docker containers using intuitive slash commands, helping DevOps teams collaborate more efficiently.
- Container Management: Start, stop, restart, pause, unpause, and delete containers
- Real-time Monitoring: Stream live container logs directly to Discord
- Resource Control: Set CPU and memory limits for containers
- System Health: Monitor container health status and system-wide Docker information
- Role-based Access Control: Two permission levels (Admin and Dev)
- Audit Logging: Comprehensive logging of all commands and role changes
- Secure Command Execution: Input sanitization to prevent command injection
- Resource Usage Alerts: Receive notifications when containers exceed CPU thresholds
- Health Checks: Verify container health status with detailed reports
/add [role] [user]
- Add a user as an Admin or Dev (Admin only)/remove [role] [user]
- Remove a user from Admin or Dev role (Admin only)/roles
- View current Admins and Devs/audit_roles
- View the role change audit log (Admin only)
/docker execute [action] [container_name]
- Execute Docker container management commands/docker logs [container_name] [timeframe] [search]
- Retrieve filtered container logs/docker limit [container_name] [cpu] [memory]
- Set resource limits for a container/docker images [action] [image_name]
- Manage Docker images (list, pull, remove)/docker prune [all]
- Prune Docker images/list
- List all Docker containers/follow [container_name]
- Follow live logs of a Docker container/stop
- Stop an active log stream/health [container_name]
- Check the health of a Docker container
/system
- Get system-wide Docker information/uptime
- Get system uptime/ping
- Check if the bot is responsive/audit [timeframe]
- Review command execution history
- Docker installed on your host machine
- Discord Bot Token
- Appropriate server permissions to add and configure bots
- Clone this repository to your server
git clone https://github.com/catalogfi/garden-guardian.git
cd garden-guardian
- Create a configuration file at
config/config.json
:
{
"token": "YOUR_DISCORD_BOT_TOKEN",
"bot_name": "Garden Guardian",
"timezone_offset": 0,
"admins": [123456789012345678],
"devs": [987654321098765432],
"allowed_user_ids": [123456789012345678, 987654321098765432],
"alert_channel_id": 123456789012345678,
"status": {
"type": "watching",
"message": "your containers grow 🌱"
}
}
-
Add a bot avatar image named
avatar.png
to the root directory -
Build and run the Docker container:
docker run -d \
--name garden-guardian \
--restart always \
-v /var/run/docker.sock:/var/run/docker.sock \
-v $(pwd)/config:/usr/src/app/config \
ghcr.io/catalogfi/garden-guardian:latest
To deploy the garden-guardian
container from GitHub Container Registry (GHCR), use the provided docker-compose.yml
file.
- Ensure Docker and Docker Compose are installed on your system.
- Pull the latest image and start the container:
docker-compose up -d
- The container will automatically restart if it stops, ensuring continuous operation.
/var/run/docker.sock:/var/run/docker.sock
: Allows the container to interact with the Docker daemon../config:/usr/src/app/config
: Mounts the localconfig
directory for configuration files.
To stop the container, run:
docker-compose down
- Create a new application in the Discord Developer Portal
- Add a bot to your application
- Enable the Server Members Intent
- Generate an invite link with the
bot
andapplications.commands
scopes - Invite the bot to your server
- The bot requires access to the Docker socket, which is a privileged resource
- Only add trusted users as Admins as they can execute potentially destructive Docker commands
- Command inputs are sanitized with
shlex.quote()
to prevent command injection - All commands are logged for audit purposes
- Bot not responding to commands: Ensure you've properly synced slash commands by checking the console output when the bot starts up
- Permission errors: Verify Docker socket permissions and that the container has appropriate access
- Command not found: Ensure you're using the correct command syntax with appropriate parameters
Use the /follow
command to stream container logs directly to Discord for real-time debugging.
The ALERT_THRESHOLD
constant (default: 50%) in the code determines when CPU usage alerts are triggered. Modify this value to adjust sensitivity.
To modify log retention policies, adjust the Docker log options for your containers:
docker run --log-opt max-size=10m --log-opt max-file=3 your-container
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
Developed by Catalog.fi