forked from Femcoders-Travellers/DreamRoute
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
103 lines (85 loc) · 3.53 KB
/
docker-compose.yml
File metadata and controls
103 lines (85 loc) · 3.53 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# Docker Compose configuration for DreamRoute SpringBoot application
services:
# SpringBoot application service
dreamroute-app:
# Build configuration - builds from local Dockerfile
build:
context: . # Build context is current directory
dockerfile: Dockerfile # Use Dockerfile in current directory
# Custom container name for easier identification
container_name: dreamroute-springboot
# Port mapping: host:container
# Maps host port 8080 to container port 8080
ports:
- "8080:8080"
# Environment variables passed to the SpringBoot application
environment:
SPRING_PROFILES_ACTIVE: docker # Activates Docker-specific configuration profile
SERVER_PORT: 8080 # Sets the server port inside container
DB_URL: jdbc:mysql://dreamroute-db:3306/dreamroute # Database connection URL using service name
DB_USERNAME: ${DB_USERNAME} # Database username
DB_PASSWORD: ${DB_PASSWORD} # Database password
# Restart policy - restarts container unless explicitly stopped
restart: unless-stopped
# Service dependencies - ensures database is healthy before starting app
depends_on:
dreamroute-db:
condition: service_healthy # Wait for DB health check to pass
# Health check configuration for the SpringBoot application
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/health"] # Health check command
interval: 30s # Check every 30 seconds
timeout: 10s # Timeout after 10 seconds
retries: 3 # Retry 3 times before marking as unhealthy
start_period: 60s # Wait 60 seconds before starting health checks
# Connect to custom network
networks:
- dreamroute-network
# MySQL database service
dreamroute-db:
# Use official MySQL 8.0 image from Docker Hub
image: mysql:8.0
# Custom container name for easier identification
container_name: dreamroute-db
# MySQL environment variables for database initialization
environment:
MYSQL_DATABASE: dreamroute # Creates database named 'dreamroute'
MYSQL_USER: ${DB_USERNAME} # Creates user 'dreamroute'
MYSQL_PASSWORD: ${DB_PASSWORD} # Sets password for 'dreamroute' user
MYSQL_ROOT_PASSWORD: root123 # Sets root user password
# Port mapping: host:container
# Maps host port 3306 to container port 3306 for external access
ports:
- "3306:3306"
# Volume mounting for data persistence
# Maps named volume 'mysql_data' to MySQL data directory
volumes:
- mysql_data:/var/lib/mysql
# Restart policy - restarts container unless explicitly stopped
restart: unless-stopped
# Health check configuration for MySQL database
healthcheck:
test: [
"CMD",
"mysqladmin", # MySQL admin utility
"ping", # Ping command to check if MySQL is responding
"-h",
"localhost", # Connect to localhost
"-u",
"dreamroute", # Use dreamroute user for health check
"-pdreamroute123", # Password for dreamroute user
]
interval: 10s # Check every 10 seconds
timeout: 5s # Timeout after 5 seconds
retries: 5 # Retry 5 times before marking as unhealthy
start_period: 30s # Wait 30 seconds before starting health checks
# Connect to custom network
networks:
- dreamroute-network
# Network configuration
networks:
dreamroute-network:
driver: bridge # Use bridge driver for container-to-container communication
# Volume configuration
volumes:
mysql_data: # Named volume for MySQL data persistence