Complete guide for setting up and managing TutorBot with Docker.
This guide covers Docker configuration, deployment, and management for the TutorBot application. Docker provides a consistent environment across development and production.
Before setting up Docker, ensure you have:
# Build and start the application
docker-compose up --build -d
# View logs
docker-compose logs -f tutorbot
# Check status
docker-compose ps
# Stop the application
docker-compose down
# Stop and remove volumes
docker-compose down -v
Located at Dockerfile:
FROM python:3.9-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
EXPOSE 5000
CMD ["python", "main.py"]
Located at docker-compose.yml:
version: '3.8'
services:
tutorbot:
build: .
ports:
- "5000:5000"
environment:
- FLASK_ENV=production
volumes:
- .:/app
restart: unless-stopped
# Build and start
docker-compose up --build
# Start in background
docker-compose up -d
# Stop application
docker-compose down
# View logs
docker-compose logs -f tutorbot
# Restart application
docker-compose restart tutorbot
# Build without cache
docker-compose build --no-cache
# Run with specific environment
docker-compose -f docker-compose.yml -f docker-compose.dev.yml up
# Execute commands in container
docker-compose exec tutorbot python main.py
docker-compose exec tutorbot bash
# View container status
docker-compose ps
# View resource usage
docker stats
# Inspect container
docker-compose exec tutorbot env
docker-compose exec tutorbot cat /app/main.py
The application uses environment variables from .env file:
# Export environment variables
source scripts/dev/export_env.sh
# Or use Docker Compose env_file
docker-compose --env-file .env up
The application mounts the current directory to /app in the container:
volumes:
- .:/app
This allows for:
.dockerignore to exclude unnecessary files# Check logs
docker-compose logs tutorbot
# Check container status
docker-compose ps
# Verify environment variables
docker-compose exec tutorbot env
# Check what's using the port
sudo netstat -tulpn | grep :5000
# Use different port
docker-compose up -p 5001:5000
# Fix file permissions
chmod -R 755 .
# Run as specific user
docker-compose exec -u 1000:1000 tutorbot bash
# Clean build
docker-compose build --no-cache
# Check Dockerfile syntax
docker build -t test .
# Verify requirements.txt
docker-compose exec tutorbot pip list
The application should respond to health checks:
# Test application health
curl http://localhost:5000/health
# Check container health
docker-compose ps
If using external databases:
# Test database connection
docker-compose exec tutorbot python -c "import requests; print('DB OK')"
For production, consider using a multi-stage build:
# Build stage
FROM python:3.9-slim as builder
WORKDIR /app
COPY requirements.txt .
RUN pip install --user -r requirements.txt
# Production stage
FROM python:3.9-slim
WORKDIR /app
COPY --from=builder /root/.local /root/.local
COPY . .
ENV PATH=/root/.local/bin:$PATH
EXPOSE 5000
CMD ["python", "main.py"]
version: '3.8'
services:
tutorbot:
build: .
ports:
- "5000:5000"
environment:
- FLASK_ENV=production
restart: unless-stopped
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:5000/health"]
interval: 30s
timeout: 10s
retries: 3
# Development setup
FLASK_ENV=development
DEBUG_MODE=console
# Start with debug
docker-compose up --build
# Production setup
FLASK_ENV=production
DEBUG_MODE=disabled
# Start with restart policy
docker-compose up -d --restart unless-stopped
# Development
docker-compose -f docker-compose.yml -f docker-compose.dev.yml up
# Production
docker-compose -f docker-compose.yml -f docker-compose.prod.yml up
# Run test suite
docker-compose exec tutorbot python run_tests.py
# Run specific tests
docker-compose exec tutorbot python run_tests.py --category core
# Run with verbose output
docker-compose exec tutorbot python run_tests.py --verbose
# Enable debug mode
docker-compose exec tutorbot ./scripts/debug_toggle.sh on
# Run tests with debug
docker-compose exec tutorbot python run_tests.py
# Check debug logs
docker-compose logs -f tutorbot
# Remove unused containers
docker container prune
# Remove unused images
docker image prune
# Remove unused volumes
docker volume prune
# Remove everything unused
docker system prune -a
# Backup container data
docker-compose exec tutorbot tar -czf backup.tar.gz /app/data
# Restore from backup
docker-compose exec tutorbot tar -xzf backup.tar.gz -C /app
Last Updated: August 2025
Version: 2.0
Maintainer: Stephen Adei