-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
55 lines (52 loc) · 1.38 KB
/
Copy pathdocker-compose.yml
File metadata and controls
55 lines (52 loc) · 1.38 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
services:
# MySQL 服务
mysql:
image: mysql:8.4
container_name: ecommerce-mysql
restart: always
environment:
# 数据库根密码
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
# 自动创建数据库
MYSQL_DATABASE: ${MYSQL_DATABASE}
# 字符集配置
MYSQL_CHARACTER_SET_SERVER: utf8mb4
MYSQL_COLLATION_SERVER: utf8mb4_unicode_ci
ports:
- "3306:3306"
volumes:
# 持久化数据(容器删除后数据不丢失)
- mysql-data:/var/lib/mysql
networks:
- ecommerce-network
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
interval: 10s
timeout: 5s
retries: 5
# Spring Boot 应用服务
app:
build: .
container_name: ecommerce-app
restart: always
ports:
- "${APP_PORT:-8080}:8080"
environment:
- DB_HOST=${DB_HOST}
- DB_USERNAME=${DB_USERNAME}
- DB_PASSWORD=${DB_PASSWORD}
# 可通过此变量覆盖容器内端口(与 server.port 对应),默认 8080
- SERVER_PORT=8080
# 依赖 MySQL 服务,确保先启动 MySQL
depends_on:
mysql:
condition: service_healthy
networks:
- ecommerce-network
# 网络配置(让两个容器在同一网络,可互相访问)
networks:
ecommerce-network:
driver: bridge
# 数据卷(持久化 MySQL 数据)
volumes:
mysql-data: