Files

2.6 KiB

Docker Setup Guide

Prerequisites

  • Docker installed on your system
  • Docker Compose (optional, but recommended)

Configuration

  1. Create a .env file in the project root with your Discord bot credentials:

    cp .env.example .env
    
  2. Edit the .env file and add your Discord bot token and other credentials:

    DISCORD_TOKEN=your_discord_bot_token_here
    CLIENT_ID=your_client_id_here
    OPENROUTER_API_KEY=your_openrouter_api_key_here
    

Start the bot:

docker-compose up -d

View logs:

docker-compose logs -f

Stop the bot:

docker-compose down

Restart the bot:

docker-compose restart

Rebuild and start (after code changes):

docker-compose up -d --build

Running with Docker directly

Build the image:

docker build -t kekbot:latest .

Run the container:

docker run -d \
  --name kekbot \
  --env-file .env \
  --restart unless-stopped \
  kekbot:latest

View logs:

docker logs -f kekbot

Stop the container:

docker stop kekbot
docker rm kekbot

Deploy Commands

Before running the bot for the first time, you may need to deploy slash commands:

# Using Docker Compose
docker-compose run --rm kekbot npm run deploy

# Using Docker directly
docker run --rm --env-file .env kekbot:latest npm run deploy

Troubleshooting

Check if container is running:

docker ps

View all containers (including stopped):

docker ps -a

Access container shell:

docker exec -it kekbot sh

View container resource usage:

docker stats kekbot

Production Considerations

  1. Security: Ensure your .env file is never committed to version control
  2. Logging: Configure log rotation if using volume mounts for logs
  3. Updates: Regularly update the base image and dependencies
  4. Monitoring: Consider adding monitoring tools like Prometheus or Grafana
  5. Backups: If you add persistent data, implement backup strategies

Multi-stage Build (Alternative)

For a smaller production image, you can use the multi-stage Dockerfile variant:

# Development stage
FROM node:20-alpine AS development
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .

# Production stage
FROM node:20-alpine AS production
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
RUN addgroup -g 1001 -S nodejs && \
    adduser -S nodejs -u 1001 && \
    chown -R nodejs:nodejs /app
USER nodejs
CMD ["npm", "start"]