Overview
TikTok Miner provides a complete Docker setup with multi-service orchestration via Docker Compose. The application includes PostgreSQL, Redis, the main web application, a background worker, and optional services for development and production environments.Architecture
The Docker setup includes the following services:- postgres: PostgreSQL 14 database with TimescaleDB support
- redis: Redis 7 for job queues and caching
- app: Main Next.js application
- worker: Background job processor for discovery pipelines
- nginx: Reverse proxy (production profile)
- pgadmin: Database management UI (development profile)
Quick Start
Prerequisites
- Docker 20.10 or higher
- Docker Compose 1.29 or higher
- At least 4GB of available RAM
Basic Setup
- Clone the repository and navigate to the project directory:
- Create environment file:
- Set required environment variables in
.env:
- Start all services:
- Check service health:
Docker Compose Configuration
PostgreSQL Service
The PostgreSQL service uses the official Alpine image with health checks:- Automatic health monitoring
- Persistent data storage
- Configurable password via environment variable
Redis Service
Redis is used for job queues and caching:- Password-protected access
- Data persistence
- Health monitoring
Application Service
The main Next.js application:- Waits for database and Redis to be healthy before starting
- Automatic Prisma migrations on startup
- Persistent upload storage
Worker Service
Background job processor for creator discovery and data scraping:- Shares database with main app
- Processes queued jobs from Redis
- Automatic restart on failure
Dockerfile Details
The application uses a multi-stage Dockerfile based on Bun:- Bun runtime for fast installation and execution
- Node.js 20 for compatibility
- Prisma client generation during build
- Automatic migrations on container start
- CLI tool compilation
Production Deployment
Using Nginx Profile
For production deployments with SSL/TLS support:- Create nginx configuration:
-
Add your SSL certificates to
nginx/ssl/ -
Create
nginx/nginx.conf:
- Start with production profile:
Environment Variables for Production
Ensure these are set in your production.env:
Resource Limits
Add resource constraints for production:Development Setup
Using pgAdmin Profile
For database management during development:http://localhost:5050:
- Email:
[email protected](or setPGADMIN_EMAIL) - Password:
admin(or setPGADMIN_PASSWORD)
Common Operations
View Logs
Restart Services
Run Database Migrations
Access Database Shell
Access Redis CLI
Execute Scripts
Backup Database
Restore Database
Volumes
Persistent data is stored in Docker volumes:postgres_data: Database filesredis_data: Redis persistenceapp_uploads: User-uploaded filesnginx_cache: Nginx cache (production)pgadmin_data: pgAdmin configuration (development)
Backup Volumes
Restore Volumes
Networking
All services run on a custom network:tiktok-miner-network
Services can communicate using their service names:
postgres:5432redis:6379app:3000
Troubleshooting
Container Won’t Start
Database Connection Issues
Redis Connection Issues
Migration Failures
Performance Issues
Security Best Practices
- Change default passwords: Always set strong passwords for
DB_PASSWORDandREDIS_PASSWORD - Use secrets: For production, use Docker secrets instead of environment variables
- Limit network exposure: Don’t expose database ports in production
- Regular updates: Keep Docker images up to date
- HTTPS only: Always use nginx with SSL in production
- API key rotation: Regularly rotate API keys and tokens
Next Steps
Environment Variables
Configure all required environment variables
Database Setup
Learn about database schema and migrations