ccccccc / docker-compose.single.yml
cnmksjs's picture
Upload 49 files
24fd742 verified
version: '3.8'
# 单容器部署配置 - 前后端在同一个容器中
services:
# MongoDB数据库
mongo:
image: mongo:7.0
container_name: chat-mongo-single
restart: unless-stopped
environment:
MONGO_INITDB_ROOT_USERNAME: admin
MONGO_INITDB_ROOT_PASSWORD: password123
MONGO_INITDB_DATABASE: chatapp
ports:
- "27017:27017"
volumes:
- mongo_data_single:/data/db
- ./mongo-init.js:/docker-entrypoint-initdb.d/mongo-init.js:ro
networks:
- chat-network-single
healthcheck:
test: ["CMD", "mongosh", "--eval", "db.adminCommand('ping')"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
# 聊天应用(前端+后端)
chat-app:
build:
context: .
dockerfile: Dockerfile
container_name: chat-app-single
restart: unless-stopped
environment:
- NODE_ENV=production
- MONGODB_URI=mongodb://admin:password123@mongo:27017/chatapp?authSource=admin
- JWT_SECRET=your-super-secret-jwt-key-change-this-in-production
- PORT=5000
- CLIENT_URL=http://localhost
ports:
- "80:80" # 前端 (nginx)
- "5000:5000" # 后端API
depends_on:
mongo:
condition: service_healthy
networks:
- chat-network-single
healthcheck:
test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:80"]
interval: 30s
timeout: 10s
retries: 3
start_period: 60s
volumes:
mongo_data_single:
networks:
chat-network-single:
driver: bridge