DockerCompose常用软件配置

Java常用软件配置

配置

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
153
154
155
version: '3.8'
services:
# mysql8
mysql3307:
container_name: mysql3307
image: mysql:8
ports:
# 主机端口3307
- "3307:3306"
volumes:
# 挂载目录
- "/opt/mysql/conf.d:/etc/mysql/conf.d"
- "/opt/mysql/data:/var/lib/mysql"
environment:
# Mysql密码
MYSQL_ROOT_PASSWORD: 123456
# redis
redis6380:
container_name: redis6380
image: redis
# 启动redis 并设置密码
command: redis-server --requirepass 123456 --appendonly yes
ports:
- "6380:6379"
volumes:
- "/opt/redis/data:/data"
nginx:
container_name: nginx
image: nginx
ports:
- "80:80"
- "443:443"
volumes:
- "/opt/project/project:/opt/project/project"
- "/opt/project/nginx/nginx.conf:/etc/nginx/nginx.conf"
- "/opt/project/nginx/log:/var/log/nginx"
# nacos
nacos8849:
container_name: nacos8849
image: nacos/nacos-server
environment:
PREFER_HOST_MODE: hostname #如果支持主机名可以使用hostname,否则使用ip,默认也是ip
SPRING_DATASOURCE_PLATFORM: mysql #数据源平台 仅支持mysql或不保存empty
MODE: standalone
# 连接mysql
MYSQL_SERVICE_HOST: mysql3307
MYSQL_SERVICE_DB_NAME: nacos_config
MYSQL_SERVICE_PORT: 3307
MYSQL_SERVICE_USER: root
MYSQL_SERVICE_PASSWORD: 123456
JVM_XMS: 512m
JVM_MMS: 320m
links:
- mysql3307
ports:
- "8849:8848"
volumes:
- "/opt/nacos/plugins:/home/nacos/plugins"
- "/opt/nacos/logs:/home/nacos/logs"
- "/opt/nacos/application.properties:/home/nacos/conf/application.properties"
# 先启动 mysql和redis再启动nacos
depends_on:
- mysql3307
- redis6380
# seata
seata:
container_name: seata
image: seataio/seata-server:1.1.0
hostname: seata
ports:
- "8091:8091"
environment:
# 写主机可以访问的外网ip地址
- SEATA_IP=127.0.0.1
- SEATA_CONFIG_NAME=file:/seata-server/resources/registry
links:
- nacos8849
- mysql3307
depends_on:
- nacos8849
- mysql3307
volumes:
- "/opt/test/seata/conf/registry.conf:/seata-server/resources/registry.conf"
- "/opt/test/seata/conf/file.conf:/seata-server/resources/file.conf"
- "/opt/test/seata/logs:/root/logs/seata"
# elasticSearch
elasticSearch:
container_name: es
image: elasticsearch:7.6.2
environment:
- cluster.name=es1
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
# 单机模式
- "discovery.type=single-node"
ulimits:
memlock:
soft: -1
hard: -1
ports:
- "9200:9200"
- "9300:9300"
volumes:
- "/opt/test/es/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml"
- "/opt/test/es/plugins:/usr/share/elasticsearch/plugins"
- "/opt/test/es/data:/usr/share/elasticsearch/data"
# rabbitmq
rabbitmq:
container_name: rabbitmq
image: library/rabbitmq:3.8-management
ports:
- "5672:5672"
- "15672:15672"
- "25672:25672"
volumes:
- "/opt/test/rabbitmq:/var/lib/rabbitmq"
# yapi 默认密码是 ymfe.org
yapi:
image: mrjin/yapi:latest
privileged: true
container_name: yapi
environment:
- VERSION=1.5.6
- LOG_PATH=/tmp/yapi.log
- HOME=/home
- PORT=3000
- ADMIN_EMAIL=管理员邮箱
- DB_SERVER=mongo
- DB_NAME=yapi
- DB_PORT=27017
ports:
- 3000:3000
depends_on:
- mongo
# mongo数据库
mongo:
image: mongo
container_name: mongo
privileged: true
ports:
- 27017:27017
# java程序
test-java:
container_name: test-java
# 指定Dockerfile的位置,如果是当前目录就是 .
build: java/
ports:
- "6001:6001"
volumes:
- "/opt/logs:/opt/logs"
- "/opt/nginx/html/imgs/test:/opt/nginx/html/imgs/test"
# 引入后,可以在java配置文件中直接连接数据库 不需要写ip地址
links:
- nacos8849
- mysql3307
- redis6380

java yml配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
password: 123456
spring:
datasource:
druid:
# 直接写容器名称即可
url: jdbc:mysql://mysql3307/test?characterEncoding=utf8&useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true
username: root
password: ${password}
redis:
# 直接写容器名称即可
host: redis6380
password: ${password}
# 写容器的端口号,不是主机端口
port: 6379
cloud:
nacos:
discovery:
# nacos不用写端口,默认容器端口8848
server-addr: nacos8849

相关文章

SpringCloud

服务注册与发现

服务调用

SpringCloud-OpenFeign问题

SpringCloud-GateWay工具类

SpringQuartz动态定时任务

Redis集群搭建

redis分布式锁

服务链路追踪

K8S