Overview
Docker Compose provides a simpler way to manage your Bot Planning deployment by defining all configuration in a single YAML file. This approach is ideal for development and production environments where you want reproducible deployments.Prerequisites
- Docker and Docker Compose installed on your system
- A Discord bot token from Discord Developer Portal
- Google Sheets URL for your planning/schedule (exported as CSV)
Docker Compose Setup
- Basic Setup
- Production Setup
- Development Setup
Create a Configuration explained:
docker-compose.yml file in your project directory:docker-compose.yml
build: .- Builds the Docker image from the current directory’s Dockerfilecontainer_name- Assigns a friendly name for easy managementenv_file- Loads environment variables from.envfilerestart: always- Automatically restarts the container on failure or system rebootlogging- Limits log file size to prevent disk space issues
Environment Configuration
Create a.env file in the same directory as your docker-compose.yml:
.env
Security Tip: Never commit your
.env file to version control. Add it to .gitignore to keep your credentials safe.Deployment Steps
Create Discord Bot
Navigate to the Discord Developer Portal and create a new bot application. Copy your bot token.
Prepare Configuration Files
Create both
docker-compose.yml and .env files in your project directory with the appropriate configuration.Start the Bot
Launch the bot using Docker Compose:The
-d flag runs the container in detached mode (background). Docker Compose will:- Build the Docker image if it doesn’t exist
- Create and start the container
- Apply all configuration from
docker-compose.yml
Managing the Deployment
View Status
View Logs
Stop the Bot
Start the Bot
Restart the Bot
Stop and Remove Containers
Stop and Remove Everything
Updating the Bot
When you update the bot code:Docker Compose automatically handles stopping the old container and starting the new one, making updates seamless.
Advanced Configuration
Multiple Environment Files
You can use different environment files for different deployments:docker-compose.yml
Custom Network
If you need the bot to communicate with other containers:docker-compose.yml
Volume for Persistent Data
If your bot generates files you want to persist:docker-compose.yml
Restart Policies
Docker Compose supports several restart policies:| Policy | Description | Use Case |
|---|---|---|
no | Never restart | Testing only |
always | Always restart, even after manual stop | Critical production services |
unless-stopped | Restart unless manually stopped | Most production services |
on-failure | Restart only if exit code is non-zero | Services with built-in error handling |
Recommended: Use
unless-stopped for production. This restarts the bot automatically on system reboot but respects manual stops, giving you control during maintenance.Troubleshooting
Service Fails to Start
View detailed logs:Configuration Changes Not Applied
Rebuild the image:Port Conflicts
If you need to expose ports and encounter conflicts, modifydocker-compose.yml:
Environment Variables Not Loading
Verify.env file location and format:
= sign:
Resource Limits
If the bot is using too many resources, add limits:docker compose (v2) instead of docker-compose (v1) for deploy section to work in standalone mode.
Comparison: Docker vs Docker Compose
| Feature | Docker | Docker Compose |
|---|---|---|
| Command length | Long, complex | Short, simple |
| Configuration | Command-line arguments | YAML file |
| Reproducibility | Manual documentation needed | Self-documented |
| Multi-container | Complex | Easy |
| Environment management | --env-file flag | Built-in support |
| Best for | Simple, one-off deployments | Production, team projects |
Recommendation: Use Docker Compose for any deployment you plan to maintain long-term. The configuration file serves as documentation and makes deployments consistent across environments.