This Discord bot allows you to manage Docker containers directly from a Discord server using slash commands. It provides functionalities such as starting, stopping, and restarting containers, listing running containers, and showing logs of a specific container.
- Container Management: Supports starting, stopping, and restarting Docker containers via simple commands.
- List Running Containers: Displays a list of containers currently running.
- View Logs: Shows the last 50 log entries of a specified container.
- Integration with Docker and Discord: Utilizes the official Docker Python client (
docker-py
) anddiscord.py
library for seamless interaction.
/docker <container_name> <action>
: Manages containers with the actionsstart
,stop
, orrestart
. Example:/docker my_container start
./list_containers
: Lists all containers currently in therunning
state./container_logs <container_name>
: Shows the logs for a specific container.
DISCORD_TOKEN
: The token for your Discord bot.
Here’s an example of how to configure the bot using docker-compose
:
services:
discord-bot:
container_name: discord_docker_bot
image: manucarcor/discord_docker_bot:latest
environment:
- DISCORD_TOKEN=your_discord_token
volumes:
- /var/run/docker.sock:/var/run/docker.sock
restart: unless-stopped
To use this bot, you need to create a bot in the Discord Developer Portal:
- Go to the Discord Developer Portal.
- Click on New Application and give it a name.
- On the application page, go to the Bot section and click Add Bot.
- Copy the Token from this page (you’ll use it in your
docker-compose.yml
underDISCORD_TOKEN
).
To ensure the bot has the correct permissions:
- In the OAuth2 section, go to URL Generator.
- Under OAuth2 Scopes, select
bot
andapplications.commands
(for slash commands). - Under Bot Permissions, check the necessary permissions for the bot, such as:
Send Messages
Read Messages/View Channels
Manage Messages
- Copy the generated URL and paste it into your browser to invite the bot to your server.
Use the URL generated in the previous step to invite the bot to your server. The bot will now be able to interact with the server where it’s invited, using the correct permissions.
-
Run the Bot: Ensure that your
docker-compose.yml
is configured correctly with the necessary environment variables. Then, run the following command to bring up the container:docker-compose up -d
-
Commands in Discord: From any channel in the server where the bot is active, you can execute commands such as:
/docker <container_name> start
: Start a specific container./list
: List all running containers./contrainer_logs <container_name>
: Logs of containers.
- Docker: The image requires Docker to manage containers on your server.
- Discord Bot: You need to register a Discord bot and obtain its token from the Discord Developer Portal.
- Docker Permissions: Ensure that the bot's container has access to Docker on the host machine where it is running.
This project is open for contributions. If you want to add new features, fix bugs, or add support for more languages, feel free to submit a pull request on the linked GitHub repository.