Repository navigation
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
56 lines (51 loc) · 2.02 KB
/
Copy pathdocker-compose.yml
File metadata and controls
56 lines (51 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
version: '3.8' # Docker Compose file format version
services: # "services" = containers we want to run
# Service 1: MongoDB
mongodb:
image: mongo:7.0 # Download official MongoDB 7.0 from Docker Hub
container_name: video-app-mongodb # Give it a friendly name
restart: unless-stopped # Auto-restart if it crashes
ports:
- "27017:27017" # Expose port: YOUR_COMPUTER:CONTAINER
# Makes MongoDB accessible at localhost:27017
environment:
MONGO_INITDB_DATABASE: video_app # Create database named "video_app"
volumes:
- mongodb_data:/data/db # Save data to persistent volume
# (data survives container restarts)
networks:
- video-app-network # Put on custom network
healthcheck: # Check if MongoDB is ready
test: echo 'db.runCommand("ping").ok' | mongosh localhost:27017/video_app --quiet
interval: 10s # Check every 10 seconds
timeout: 5s
retries: 5
# Service 2: Flask Backend
backend:
build:
context: ./ # Build from current directory
dockerfile: Dockerfile # Use our Dockerfile
container_name: video-app-backend
restart: unless-stopped
ports:
- "5000:5000" # Expose Flask on port 5000
environment:
# Environment variables for the backend
- MONGODB_URI=mongodb://mongodb:27017/video_app
# "mongodb" here refers to the service name above
# Docker DNS resolves "mongodb" to the container's IP
- JWT_SECRET_KEY=your_secret_key
- FLASK_ENV=production
depends_on:
mongodb:
condition: service_healthy # Wait for MongoDB to be ready
networks:
- video-app-network # Same network as MongoDB
command: sh -c "python seed_videos.py && python app.py"
# First seed the database, then start Flask
volumes:
mongodb_data: # Named volume for MongoDB data persistence
driver: local # Store on local disk
networks:
video-app-network: # Custom network for service communication
driver: bridge