Skip to main content

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

Create a docker-compose.yml file in your project directory:
docker-compose.yml
version: '3.8'

services:
  bot-planning:
    build: .
    container_name: bot-planning
    env_file:
      - .env
    restart: always
    logging:
      driver: "json-file"
      options:
        max-size: "10m"
        max-file: "3"
Configuration explained:
  • build: . - Builds the Docker image from the current directory’s Dockerfile
  • container_name - Assigns a friendly name for easy management
  • env_file - Loads environment variables from .env file
  • restart: always - Automatically restarts the container on failure or system reboot
  • logging - 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
DISCORD_TOKEN=your_discord_bot_token_here
EDT_PATH=https://docs.google.com/spreadsheets/d/YOUR_SHEET_ID/export?format=csv
Security Tip: Never commit your .env file to version control. Add it to .gitignore to keep your credentials safe.

Deployment Steps

1

Create Discord Bot

Navigate to the Discord Developer Portal and create a new bot application. Copy your bot token.
2

Prepare Configuration Files

Create both docker-compose.yml and .env files in your project directory with the appropriate configuration.
3

Start the Bot

Launch the bot using Docker Compose:
docker-compose up -d
The -d flag runs the container in detached mode (background). Docker Compose will:
  1. Build the Docker image if it doesn’t exist
  2. Create and start the container
  3. Apply all configuration from docker-compose.yml
4

Verify Deployment

Check container status:
docker-compose ps
View logs:
docker-compose logs
Follow logs in real-time:
docker-compose logs -f

Managing the Deployment

View Status

docker-compose ps

View Logs

# All logs
docker-compose logs

# Follow logs in real-time
docker-compose logs -f

# Last 100 lines
docker-compose logs --tail=100

Stop the Bot

docker-compose stop
This stops the container but preserves it for later restart.

Start the Bot

docker-compose start

Restart the Bot

docker-compose restart

Stop and Remove Containers

docker-compose down
This stops and removes containers, but keeps the built image.

Stop and Remove Everything

docker-compose down --rmi all -v
Removes containers, images, and volumes.

Updating the Bot

When you update the bot code:
1

Pull Latest Code

If using version control:
git pull
2

Rebuild and Restart

docker-compose up -d --build
The --build flag forces a rebuild of the image with the new code.
3

Verify Update

Check logs to ensure the bot started correctly:
docker-compose logs -f
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
services:
  bot-planning:
    build: .
    env_file:
      - .env
      - .env.production
Then run with:
docker-compose --env-file .env.production up -d

Custom Network

If you need the bot to communicate with other containers:
docker-compose.yml
version: '3.8'

services:
  bot-planning:
    build: .
    container_name: bot-planning
    env_file:
      - .env
    restart: always
    networks:
      - bot-network

networks:
  bot-network:
    driver: bridge

Volume for Persistent Data

If your bot generates files you want to persist:
docker-compose.yml
services:
  bot-planning:
    build: .
    container_name: bot-planning
    env_file:
      - .env
    restart: always
    volumes:
      - bot-data:/app/data

volumes:
  bot-data:

Restart Policies

Docker Compose supports several restart policies:
PolicyDescriptionUse Case
noNever restartTesting only
alwaysAlways restart, even after manual stopCritical production services
unless-stoppedRestart unless manually stoppedMost production services
on-failureRestart only if exit code is non-zeroServices 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:
docker-compose logs bot-planning
Check service status:
docker-compose ps

Configuration Changes Not Applied

Rebuild the image:
docker-compose up -d --build --force-recreate

Port Conflicts

If you need to expose ports and encounter conflicts, modify docker-compose.yml:
services:
  bot-planning:
    ports:
      - "8080:8080"  # host:container

Environment Variables Not Loading

Verify .env file location and format:
cat .env
Ensure no spaces around the = sign:
# Correct
DISCORD_TOKEN=abc123

# Incorrect
DISCORD_TOKEN = abc123

Resource Limits

If the bot is using too many resources, add limits:
services:
  bot-planning:
    deploy:
      resources:
        limits:
          cpus: '0.5'
          memory: 512M
Note: Use docker compose (v2) instead of docker-compose (v1) for deploy section to work in standalone mode.

Comparison: Docker vs Docker Compose

FeatureDockerDocker Compose
Command lengthLong, complexShort, simple
ConfigurationCommand-line argumentsYAML file
ReproducibilityManual documentation neededSelf-documented
Multi-containerComplexEasy
Environment management--env-file flagBuilt-in support
Best forSimple, one-off deploymentsProduction, 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.

Build docs developers (and LLMs) love