This document explains how to run the webdev-bot using Docker.
- Docker installed (version 20.10 or higher)
- Docker Compose installed (version 2.0 or higher)
.envfile with required environment variables
The Docker setup uses .nvmrc as the single source of truth for the Node.js version. The Dockerfile automatically reads this version at build time via the NODE_VERSION build argument. No need to manually sync versions between .nvmrc and Docker files.
Before running the bot, create a .env file in the project root with the following variables:
DISCORD_TOKEN=your_discord_bot_token
CLIENT_ID=your_discord_client_idThese variables are loaded automatically by docker-compose and used by src/env.ts.
Run the bot with hot reload enabled for development:
pnpm run docker:devOr using docker-compose directly:
docker compose --profile dev upIn development mode:
- Code changes in
src/are automatically detected and the bot restarts - Full development dependencies are available
- Logs are streamed to your terminal
To stop the development container:
pnpm run docker:stop
# or
docker compose --profile dev downRun the bot in production mode with optimized image:
pnpm run docker:prodOr using docker-compose directly:
docker compose --profile prod up -dIn production mode:
- Minimal image size (only production dependencies)
- Optimized for runtime performance
- Runs in detached mode by default
To stop the production container:
docker compose --profile prod downBuild the production image:
docker build -t webdev-bot:latest \
--build-arg NODE_VERSION=$(cat .nvmrc | tr -d 'v') \
--target production .Build the development image:
docker build -t webdev-bot:dev \
--build-arg NODE_VERSION=$(cat .nvmrc | tr -d 'v') \
--target development .Run the production container manually (after building with the NODE_VERSION arg):
docker run -d \
--name webdev-bot \
--env-file .env \
--restart unless-stopped \
webdev-bot:latestRun the development container manually (after building with the NODE_VERSION arg):
docker run -it \
--name webdev-bot-dev \
--env-file .env \
-v $(pwd)/src:/app/src:ro \
webdev-bot:dev-
Check if environment variables are set correctly:
docker compose --profile dev run --rm bot-dev env | grep DISCORD -
View container logs:
docker compose --profile dev logs bot-dev # or docker logs webdev-bot-dev
If you encounter permission issues with mounted volumes, ensure that the files have appropriate read permissions:
chmod -R 644 src/
chmod 755 src/If code changes aren't being detected in development mode:
-
Verify the volume mounts are correct:
docker inspect webdev-bot-dev | grep Mounts -A 10 -
Restart the container:
docker compose --profile dev restart
The production image is optimized for size using:
- Alpine Linux base image
- Multi-stage builds (dev dependencies not included)
- Only compiled
dist/folder and production dependencies
To check image size:
docker images webdev-botIf you modify package.json or pnpm-lock.yaml, rebuild the image:
pnpm run docker:build
# or
docker compose build --no-cache- Never commit
.env- Keep your secrets secure - Use production profile for deployment - Smaller, more secure images
- Keep development profile for local testing - Faster iteration with hot reload
- Node version is managed in
.nvmrc- Update.nvmrcto change Node version for Docker - Regularly update the base image - Rebuild images after updating
.nvmrc - Monitor container resources - Use
docker statsto check resource usage
View running containers:
docker psView all containers (including stopped):
docker ps -aRemove all stopped containers:
docker compose down -vView container logs in real-time:
docker compose --profile dev logs -f bot-devExecute commands inside the container:
docker compose --profile dev exec bot-dev sh