-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
152 lines (143 loc) · 3.74 KB
/
Copy pathdocker-compose.yml
File metadata and controls
152 lines (143 loc) · 3.74 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# Docker Compose Watch Example
# This configuration demonstrates Docker Compose Watch functionality
# with different watch actions for various file types and services
version: "3.8"
services:
# Frontend service - React/Vue.js application example
frontend:
build:
context: ./frontend
dockerfile: Dockerfile
ports:
- "3000:3000"
volumes:
- ./frontend:/app
- /app/node_modules # Prevent overwriting node_modules
environment:
- NODE_ENV=development
develop:
watch:
# Sync source code changes for hot reload
- action: sync
path: ./frontend/src
target: /app/src
# Rebuild when package.json changes (new dependencies)
- action: rebuild
path: ./frontend/package.json
# Sync public assets
- action: sync
path: ./frontend/public
target: /app/public
# Backend service - Node.js/Python API example
backend:
build:
context: ./backend
dockerfile: Dockerfile
ports:
- "8000:8000"
volumes:
- ./backend:/app
- /app/node_modules # For Node.js projects
environment:
- NODE_ENV=development
- DATABASE_URL=postgresql://user:password@db:5432/devdb
depends_on:
- db
develop:
watch:
# Rebuild when dependencies change
- action: rebuild
path: ./backend/package.json # For Node.js
- action: rebuild
path: ./backend/requirements.txt # For Python
# Sync application code for hot reload
- action: sync
path: ./backend/src
target: /app/src
- action: sync
path: ./backend/app
target: /app/app
# Restart when configuration changes
- action: restart
path: ./backend/config
# Database service
db:
image: postgres:15
environment:
- POSTGRES_DB=devdb
- POSTGRES_USER=user
- POSTGRES_PASSWORD=password
ports:
- "5432:5432"
volumes:
- postgres_data:/var/lib/postgresql/data
- ./db/init.sql:/docker-entrypoint-initdb.d/init.sql
develop:
watch:
# Restart when database initialization scripts change
- action: restart
path: ./db/init.sql
# Web server - Nginx configuration example
nginx:
image: nginx:alpine
ports:
- "80:80"
volumes:
- ./nginx/nginx.conf:/etc/nginx/nginx.conf
- ./nginx/conf.d:/etc/nginx/conf.d
depends_on:
- frontend
- backend
develop:
watch:
# Restart when nginx configuration changes
- action: restart
path: ./nginx/nginx.conf
- action: restart
path: ./nginx/conf.d
# Redis cache service
redis:
image: redis:7-alpine
ports:
- "6379:6379"
volumes:
- redis_data:/data
- ./redis/redis.conf:/etc/redis/redis.conf
command: redis-server /etc/redis/redis.conf
develop:
watch:
# Restart when Redis configuration changes
- action: restart
path: ./redis/redis.conf
# Worker service - Background job processor
worker:
build:
context: ./backend
dockerfile: Dockerfile.worker
volumes:
- ./backend:/app
environment:
- NODE_ENV=development
- REDIS_URL=redis://redis:6379
depends_on:
- redis
- db
develop:
watch:
# Sync worker code changes
- action: sync
path: ./backend/workers
target: /app/workers
# Rebuild when dependencies change
- action: rebuild
path: ./backend/package.json
# Named volumes for data persistence
volumes:
postgres_data:
driver: local
redis_data:
driver: local
# Custom network for service communication
networks:
default:
driver: bridge