- Docker Desktop installed (https://www.docker.com/products/docker-desktop/)
.env.dockerfile configured with your credentials
# 1. Configure environment
cp .env.docker.example .env.docker
# Edit .env.docker and fill in your credentials
# 2. Build and start all services
docker-compose up -d
# 3. Check status
docker-compose ps
# 4. View logs
docker-compose logs -f app
# 5. Stop all services
docker-compose down-
Copy the environment template:
cp .env.docker .env.docker
-
Fill in required values in
.env.docker:Required Fields (MUST fill):
JWT_ACCESS_TOKEN_SECRET- Generate with:node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"JWT_REFRESH_TOKEN_SECRET- Generate a different secretPRIVATE_KEY- Your Ethereum wallet private key (from MetaMask)MNEMONIC- Your 12-word wallet mnemonicENCRYPTION_KEY- 32-character string for AES-256ENCRYPTION_IV- 16-character stringCLOUDINARY_*- Your Cloudinary credentials
Database Options:
The docker-compose includes local MongoDB and Redis instances by default.
- Use Local (Default): No changes needed, uses containers
- Use MongoDB Atlas: Update
MONGO_URLto your Atlas connection string - Use Upstash Redis: Update
REDIS_HOST,REDIS_PORT, and addREDIS_PASSWORD
# Build Docker image
docker-compose build
# Or build without cache
docker-compose build --no-cache# Start in detached mode (background)
docker-compose up -d
# Or start with logs (foreground)
docker-compose upExpected output:
Creating network "corechainserver_corechain-network" done
Creating corechainserver-mongo ... done
Creating corechainserver-redis ... done
Creating corechainserver-app ... done
# Check all services are running
docker-compose ps
# Should show:
# NAME STATUS PORTS
# corechainserver-app Up (healthy) 0.0.0.0:3000->3000/tcp
# corechainserver-mongo Up (healthy) 0.0.0.0:27017->27017/tcp
# corechainserver-redis Up (healthy) 0.0.0.0:6379->6379/tcpTest the application:
# Health check
curl http://localhost:3000/health
# Test blockchain endpoint
curl http://localhost:3000/blockchain/employees# All services
docker-compose logs -f
# Specific service
docker-compose logs -f app
docker-compose logs -f mongo
docker-compose logs -f redis
# Last 100 lines
docker-compose logs --tail=100 app# Restart all
docker-compose restart
# Restart specific service
docker-compose restart app# Stop without removing
docker-compose stop
# Stop and remove containers
docker-compose down
# Stop and remove containers + volumes (deletes data!)
docker-compose down -vConnect to MongoDB shell:
docker exec -it corechainserver-mongo mongosh -u admin -p admin123 --authenticationDatabase adminBackup database:
docker exec corechainserver-mongo mongodump --uri="mongodb://admin:admin123@localhost:27017/hrm-backend?authSource=admin" --out=/data/backup
docker cp corechainserver-mongo:/data/backup ./backupRestore database:
docker cp ./backup corechainserver-mongo:/data/backup
docker exec corechainserver-mongo mongorestore --uri="mongodb://admin:admin123@localhost:27017/hrm-backend?authSource=admin" /data/backupConnect to Redis CLI:
docker exec -it corechainserver-redis redis-cliClear cache:
docker exec corechainserver-redis redis-cli FLUSHALLCheck logs for errors:
docker-compose logs appCommon issues:
-
Port already in use:
Error: bind: address already in useSolution: Stop the service using the port or change the port in
docker-compose.yml -
Environment variable missing:
Error: Missing required environment variableSolution: Check
.env.dockerhas all required fields filled -
MongoDB connection failed:
Error: connect ECONNREFUSED mongo:27017Solution: Wait for MongoDB to be healthy (check with
docker-compose ps)
Check application logs:
docker-compose logs -f appRebuild container:
docker-compose down
docker-compose build --no-cache
docker-compose up -dReset MongoDB (WARNING: Deletes all data):
docker-compose down -v
docker volume rm corechainserver_mongo_data
docker-compose up -dCheck resource usage:
docker statsIncrease Docker resources:
- Open Docker Desktop → Settings → Resources
- Increase CPU and Memory limits
-
Never commit
.env.dockerto Git ✅ Already in .gitignore -
Use strong secrets:
# Generate strong random secrets node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"
-
Use managed databases in production:
- MongoDB Atlas for MongoDB
- Upstash or Redis Cloud for Redis
-
Use HTTPS:
- Deploy behind a reverse proxy (nginx, Traefik)
- Use SSL certificates (Let's Encrypt)
-
Limit exposed ports:
- Only expose port 3000 (application)
- Don't expose MongoDB/Redis ports publicly
For staging/production:
Create docker-compose.override.yml:
version: '3.8'
services:
app:
environment:
NODE_ENV: production
restart: always
# Optional: Remove local DB if using Atlas/Upstash
mongo:
profiles:
- local-only
redis:
profiles:
- local-only# View running containers
docker ps
# View all containers (including stopped)
docker ps -a
# Execute command in container
docker exec -it corechainserver-app sh
# View container resource usage
docker stats
# Clean up unused Docker resources
docker system prune -a
# View Docker volumes
docker volume ls
# Remove all stopped containers
docker container prune
# View application health
docker inspect corechainserver-app | grep -A 10 Health┌─────────────────────────────────────────┐
│ Docker Compose Network │
│ │
│ ┌──────────┐ ┌───────────┐ │
│ │ MongoDB │ │ Redis │ │
│ │ :27017 │ │ :6379 │ │
│ └─────┬────┘ └─────┬─────┘ │
│ │ │ │
│ └──────┬──────┘ │
│ │ │
│ ┌──────▼──────┐ │
│ │ CoreChain │ │
│ │ Application │ │
│ │ :3000 │ │
│ └──────┬──────┘ │
│ │ │
└───────────────┼─────────────────────────┘
│
┌──────▼──────┐
│ Sepolia │
│ Testnet │
│ (Blockchain)│
└─────────────┘
- ✅ Environment configured
- ✅ Containers running
- ✅ Application accessible at http://localhost:3000
- 📝 Update API documentation
- 🚀 Deploy to production server
- Docker Documentation: https://docs.docker.com/
- Docker Compose: https://docs.docker.com/compose/
- NestJS Docker: https://docs.nestjs.com/recipes/deployment