Skip to main content
This bot is archived and uses discord.js v12. Consider updating dependencies before production deployment.

Overview

Docker provides a containerized, portable deployment solution for Yato. While the source repository doesn’t include a Dockerfile, this guide shows you how to create one and deploy the bot in a Docker container.

Prerequisites

  • Docker installed (get Docker)
  • Docker Compose (optional, for multi-container setup)
  • Discord bot token
  • MongoDB instance or Atlas connection string

Creating a Dockerfile

Since the repository doesn’t include a Dockerfile, create one in the project root:
Dockerfile
# Use Node.js 16 (compatible with discord.js v12)
FROM node:16-alpine

# Set working directory
WORKDIR /usr/src/app

# Install build dependencies for canvas
RUN apk add --no-cache \
    build-base \
    g++ \
    cairo-dev \
    jpeg-dev \
    pango-dev \
    giflib-dev \
    pixman-dev

# Copy package files
COPY package*.json ./

# Install dependencies
RUN npm ci --only=production

# Copy application files
COPY . .

# Run as non-root user
RUN addgroup -g 1001 -S nodejs && \
    adduser -S nodejs -u 1001 && \
    chown -R nodejs:nodejs /usr/src/app

USER nodejs

# Start the bot
CMD ["node", "src/index.js"]
The canvas package requires native dependencies. Alpine Linux needs build tools and Cairo libraries.

Docker Compose setup

For a complete setup with MongoDB, create docker-compose.yml:
docker-compose.yml
version: '3.8'

services:
  yato-bot:
    build: .
    container_name: yato-bot
    restart: unless-stopped
    environment:
      - TOKEN=${TOKEN}
      - MONGO_URI=mongodb://mongodb:27017/yato
      - CLIENT_ID=${CLIENT_ID}
    depends_on:
      - mongodb
    networks:
      - yato-network

  mongodb:
    image: mongo:5
    container_name: yato-mongodb
    restart: unless-stopped
    volumes:
      - mongodb-data:/data/db
    networks:
      - yato-network
    ports:
      - "27017:27017"  # Optional: expose for external access

volumes:
  mongodb-data:

networks:
  yato-network:
    driver: bridge
This setup includes a local MongoDB container. If using MongoDB Atlas, remove the mongodb service and use your Atlas connection string.

Environment configuration

Create a .env file in the project root:
.env
TOKEN=your_discord_bot_token
CLIENT_ID=your_bot_client_id
MONGO_URI=mongodb://mongodb:27017/yato
Never commit the .env file. Ensure it’s in .gitignore.

Deployment steps

1

Clone the repository

git clone https://github.com/qonTesq/Yato.git
cd Yato
2

Create Dockerfile and docker-compose.yml

Create both files as shown above in the project root.
3

Configure environment variables

Create your .env file with the required variables:
TOKEN=your_discord_bot_token
MONGO_URI=mongodb://mongodb:27017/yato
4

Build the Docker image

docker-compose build
Or build without Compose:
docker build -t yato-bot .
5

Start the containers

docker-compose up -d
The -d flag runs containers in detached mode (background).
6

Verify the bot is running

Check container logs:
docker-compose logs -f yato-bot
You should see:
➤ Logged in as YourBotName#1234 (123456789)
✔ Connected to MongoDB

Managing your Docker deployment

View logs

docker-compose logs -f yato-bot

Restart the bot

docker-compose restart yato-bot

Stop the bot

docker-compose stop

Stop and remove containers

docker-compose down
This removes containers but preserves the mongodb-data volume. Use docker-compose down -v to delete volumes too.

Update the bot

When you update the code:
1

Pull changes

git pull origin main
2

Rebuild image

docker-compose build
3

Restart with new image

docker-compose up -d

Production deployment options

Deploy to a VPS

1

Set up a VPS

Choose a provider:
  • DigitalOcean (starting at $4/month)
  • Linode
  • Vultr
  • AWS EC2
2

Install Docker on VPS

# Ubuntu/Debian
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
sudo usermod -aG docker $USER
3

Clone repository on VPS

git clone https://github.com/qonTesq/Yato.git
cd Yato
4

Configure and deploy

Follow the deployment steps above to build and run containers.

Using Docker with MongoDB Atlas

To use MongoDB Atlas instead of a local container:
  1. Modify docker-compose.yml - remove the mongodb service:
docker-compose.yml
version: '3.8'

services:
  yato-bot:
    build: .
    container_name: yato-bot
    restart: unless-stopped
    environment:
      - TOKEN=${TOKEN}
      - MONGO_URI=${MONGO_URI}
      - CLIENT_ID=${CLIENT_ID}
    networks:
      - yato-network

networks:
  yato-network:
    driver: bridge
  1. Update .env with Atlas connection string:
.env
TOKEN=your_discord_bot_token
MONGO_URI=mongodb+srv://username:[email protected]/yato?retryWrites=true&w=majority

Running without Docker Compose

If you prefer using Docker CLI directly:
1

Build the image

docker build -t yato-bot .
2

Run MongoDB container

docker run -d \
  --name yato-mongodb \
  --network yato-net \
  -v mongodb-data:/data/db \
  mongo:5
3

Run bot container

docker run -d \
  --name yato-bot \
  --network yato-net \
  --env-file .env \
  --restart unless-stopped \
  yato-bot

Optimizing the Docker image

Multi-stage build

Reduce image size with a multi-stage Dockerfile:
Dockerfile.optimized
# Build stage
FROM node:16-alpine AS builder
WORKDIR /usr/src/app

RUN apk add --no-cache build-base g++ cairo-dev jpeg-dev pango-dev giflib-dev pixman-dev

COPY package*.json ./
RUN npm ci --only=production

# Production stage
FROM node:16-alpine
WORKDIR /usr/src/app

RUN apk add --no-cache cairo jpeg pango giflib pixman

COPY --from=builder /usr/src/app/node_modules ./node_modules
COPY . .

RUN addgroup -g 1001 -S nodejs && \
    adduser -S nodejs -u 1001 && \
    chown -R nodejs:nodejs /usr/src/app

USER nodejs

CMD ["node", "src/index.js"]

.dockerignore

Create .dockerignore to exclude unnecessary files:
.dockerignore
node_modules
npm-debug.log
.env
.git
.gitignore
.vscode
.vs
README.md
.eslintrc.json

Troubleshooting

Bot container exits immediately

Check logs for errors:
docker-compose logs yato-bot
Common issues:
  • Missing or invalid TOKEN environment variable
  • MongoDB connection failure
  • Missing dependencies for Canvas

Canvas build failures

Ensure all build dependencies are installed:
RUN apk add --no-cache build-base g++ cairo-dev jpeg-dev pango-dev giflib-dev pixman-dev

MongoDB connection refused

If using Docker Compose:
  • Ensure both services are on the same network
  • Use service name (mongodb) as hostname, not localhost
  • Check depends_on in docker-compose.yml

Out of memory errors

Increase container memory limit:
docker-compose.yml
services:
  yato-bot:
    # ... other config
    deploy:
      resources:
        limits:
          memory: 512M

Monitoring and maintenance

Health checks

Add a health check to your Dockerfile:
HEALTHCHECK --interval=30s --timeout=3s --start-period=40s \
  CMD node -e "require('discord.js')" || exit 1

Automatic restarts

The restart: unless-stopped policy in docker-compose.yml ensures the bot restarts automatically after crashes or server reboots.

Log rotation

Configure Docker logging driver to prevent disk space issues:
docker-compose.yml
services:
  yato-bot:
    # ... other config
    logging:
      driver: "json-file"
      options:
        max-size: "10m"
        max-file: "3"

Additional resources

Build docs developers (and LLMs) love