Skip to content

Commit c6ebaf1

Browse files
committed
refactor docker-compose.yml
1 parent 87dbb1d commit c6ebaf1

File tree

10 files changed

+73
-55
lines changed

10 files changed

+73
-55
lines changed

README.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,20 +121,30 @@ See More [architecture](https://github.com/xmcy0011/CoffeeChat/blob/master/docs/
121121
> PS:请切换到**master**分支,编译和运行!
122122
123123
1. 启动Server(要求安装docker desktop >= 4.0.1):
124+
124125
```bash
125126
$ git clone https://github.com/xmcy0011/CoffeeChat.git
126127
$ cd CoffeeChat/server
127128
# 从代码编译docker镜像,安装mysql,redis等依赖,并自动初始化mysql数据
128-
$ docker-compose.yml up -d
129+
$ docker-compose up -d
129130
```
130-
2. 编译客户端。推荐iOS客户端(模拟器选择iphone 11),请移步:[client](https://github.com/xmcy0011/CoffeeChat/blob/master/client/cc_flutter_app/README.md)
131-
3. iOS模拟器和app启动后,点击“注册”,更改服务器IP地址为本机IP(不需要输入端口),注册成功后,登录即可。
132-
4. 内置了2个机器人(思知和微信)和3个好友,可以测试聊天功能。
131+
132+
1. 编译客户端。推荐iOS客户端(模拟器选择iphone 11),请移步:[client](https://github.com/xmcy0011/CoffeeChat/blob/master/client/cc_flutter_app/README.md)
133+
1. iOS模拟器和app启动后,点击“注册”,更改服务器IP地址为本机IP(不需要输入端口),注册成功后,登录即可。
134+
1. 内置了2个机器人(思知和微信)和3个好友,可以测试聊天功能。
133135

134136
更多细节,请移步:
137+
135138
- [client](https://github.com/xmcy0011/CoffeeChat/blob/master/client/cc_flutter_app/README.md)
136139
- [server](https://github.com/xmcy0011/CoffeeChat/blob/master/server/src/README.md)
137140

141+
停止:
142+
143+
```bash
144+
$ cd CoffeeChat/server
145+
$ docker-compose down -v
146+
```
147+
138148
### Document
139149

140150
1. [产品介绍](https://github.com/xmcy0011/CoffeeChat/blob/master/docs/01-%E4%BA%A7%E5%93%81%E4%BB%8B%E7%BB%8D.md)
@@ -145,6 +155,7 @@ $ docker-compose.yml up -d
145155
6. [MQ在IM中的实践和选型](https://github.com/xmcy0011/CoffeeChat/blob/master/docs/06_MQ%e5%9c%a8IM%e4%b8%ad%e7%9a%84%e5%ae%9e%e8%b7%b5.md)
146156

147157
更多文章请移步:
158+
148159
- [CoffeeChat-GitBook](https://xmcy0011.github.io/CoffeeChat-GitBook/)
149160

150161
### Thinks

server/app/im_gate/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# This dockerfile uses go build, then use the ubuntu run
33
# Version: 0.1
44
# Author: xmcy0011@sina.com
5-
# Desc: 注意,编译镜像的上下文必须在src下(../../),否则会失败
5+
# Desc: 注意,编译镜像的上下文必须在server下(../../),否则会失败
66
# example: docker build -t im_gate -f . ../../
77

88
##

server/app/im_gate/gate-docker.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ WeChatRobotEncodingAESKey="vpIfV7aof4QP40EreXNAVygwy4Bx534JldY1inOETBY" # 替换
2020
# 第二个节点:处理消息收发业务
2121
[[Logic]]
2222
#Ip="172.16.0.1"
23-
Ip="im_logic"
23+
Ip="cim_logic"
2424
Port=10600
2525
MaxConnCnt=4 # 2的整数倍
2626

2727
[[Logic]]
2828
#Ip="172.16.0.1"
29-
Ip="im_logic"
29+
Ip="cim_logic"
3030
Port=10600
3131
MaxConnCnt=4 # 2的整数倍

server/app/im_http/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# This dockerfile uses go build, then use the ubuntu run
33
# Version: 0.1
44
# Author: xmcy0011@sina.com
5-
# Desc: 注意,编译镜像的上下文必须在src下(../../),否则会失败
5+
# Desc: 注意,编译镜像的上下文必须在server下(../../),否则会失败
66
# example: docker build -t im_gate -f . ../../
77

88
##

server/app/im_http/http-docker.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ ListenPort=18080
33

44
# 双机冗余,也可部署一个节点,随机数均衡法
55
[[Logic]]
6-
Ip="im_logic"
6+
Ip="cim_logic"
77
#Ip="127.0.0.1"
88
Port=10600
99

1010
[[Logic]]
11-
Ip="im_logic"
11+
Ip="cim_logic"
1212
#Ip="127.0.0.1"
1313
Port=10600

server/app/im_logic/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# This dockerfile uses go build, then use the ubuntu run
33
# Version: 0.1
44
# Author: xmcy0011@sina.com
5-
# Desc: 注意,编译镜像的上下文必须在src下(../../),否则会失败
5+
# Desc: 注意,编译镜像的上下文必须在server下(../../),否则会失败
66
# example: docker build -t im_gate -f . ../../
77

88
##

server/app/im_logic/logic-docker.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@ ListenPort=10600
44
# 主库,读写,优先写
55
[[Db]]
66
ServerName="Master"
7-
Host="mysql"
7+
Host="cim_mysql"
88
Port=3306
99
DbName="coffeechat"
1010
UserName="cim"
11-
Password="ldMe$q2Xl9GKyUxj"
11+
Password="coffeechat2022"
1212
MaxConnCnt=16
1313

1414
# 从库,只读
1515
# 可以和主库保持一致,这样则意味着不使用主从模式,此时,建议把maxconncnt调小一倍
1616
[[Db]]
1717
ServerName="Slave"
18-
Host="mysql"
18+
Host="cim_mysql"
1919
Port=3306
2020
DbName="coffeechat"
2121
UserName="cim"
22-
Password="ldMe$q2Xl9GKyUxj"
22+
Password="coffeechat2022"
2323
MaxConnCnt=16
2424

2525
#[Kafka]
@@ -29,7 +29,7 @@ MaxConnCnt=16
2929

3030
[Redis]
3131
Name="cim"
32-
Ip="redis"
32+
Ip="cim_redis"
3333
Port=6379
3434
KeyPrefix="cim|" # redis中key的统一前缀
3535
Password="coffeechat" # redis的密码,不允许为空

server/app/im_logic/logic-example.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Host="127.0.0.1"
99
Port=3306
1010
DbName="coffeechat"
1111
UserName="cim"
12-
Password="ldMe$q2Xl9GKyUxj"
12+
Password="coffeechat2022"
1313
MaxConnCnt=16
1414

1515
# 从库,只读
@@ -21,7 +21,7 @@ Host="127.0.0.1"
2121
Port=3306
2222
DbName="coffeechat"
2323
UserName="cim"
24-
Password="ldMe$q2Xl9GKyUxj"
24+
Password="coffeechat2022"
2525
MaxConnCnt=16
2626

2727
#[Kafka]

server/docker-compose.yml

Lines changed: 43 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,13 @@ services:
1111
restart: always
1212
ports:
1313
- '27017:27017'
14+
networks:
15+
- CoffeeChat
1416
environment:
1517
MONGO_INITDB_ROOT_USERNAME: root
1618
MONGO_INITDB_ROOT_PASSWORD: mongopass
17-
# mongo-express:
18-
# image: mongo-express
19-
# container_name: cim_mongo-express
20-
# restart: always
21-
# ports:
22-
# - '27018:27018'
23-
# environment:
24-
# ME_CONFIG_MONGODB_ADMINUSERNAME: root
25-
# ME_CONFIG_MONGODB_ADMINPASSWORD: mongopass
26-
# ME_CONFIG_MONGODB_URL: mongodb://root:mongopass@mongo:27017/
2719
mysql:
28-
#image: 'arm64v8/mysql:8.0.28-oracle' # mac m1
20+
# image: 'arm64v8/mysql:8.0.28-oracle' # mac m1
2921
image: 'mysql:5.7'
3022
restart: always
3123
container_name: cim_mysql
@@ -34,70 +26,83 @@ services:
3426
MYSQL_ROOT_PASSWORD: 123456
3527
MYSQL_DATABASE: coffeechat
3628
MYSQL_USER: cim
37-
MYSQL_PASSWORD: ldMe$q2Xl9GKyUxj
29+
MYSQL_PASSWORD: coffeechat2022
3830
volumes:
3931
- cim_mysql_data:/var/lib/mysql
4032
# docker-entrypoint-initdb.d:这个目录下的脚本,只在容器第一次运行时被执行。
4133
- ./setup/mysql/init/:/docker-entrypoint-initdb.d/
4234
networks:
43-
- local
35+
- CoffeeChat
4436
ports:
4537
- "3306:3306"
4638
command: [ '--default-authentication-plugin=mysql_native_password', '--character-set-server=utf8mb4',
4739
'--collation-server=utf8mb4_unicode_ci' ]
4840
redis:
49-
build: ./setup/redis
41+
build: setup/redis
5042
container_name: cim_redis
5143
volumes:
5244
- cim_redis:/data # 持久化数据,其他如密码等,在redis.conf里已配置
5345
networks:
54-
- local
46+
- CoffeeChat
5547
ports:
5648
- "6379:6379" # 端口改掉,预防攻击
5749
consul:
5850
image: bitnami/consul:latest
51+
container_name: cim_consul
5952
volumes:
6053
- cim_consul:/bitnami
6154
networks:
62-
- local
55+
- CoffeeChat
6356
ports:
6457
- '8300:8300'
6558
- '8301:8301'
6659
- '8301:8301/udp'
6760
- '8500:8500'
6861
- '8600:8600'
6962
- '8600:8600/udp'
70-
im_http: # http 服务
71-
container_name: im_http
63+
cim_http: # http 服务
64+
container_name: cim_http
7265
build: # 指定从dockerfile编译
7366
context: .
74-
dockerfile: app/im_http/Dockerfile
67+
dockerfile: ./app/im_http/Dockerfile
7568
volumes: # 数据卷绑定
7669
- ./log/http:/log
70+
deploy:
71+
restart_policy:
72+
condition: on-failure
73+
delay: 5s
74+
max_attempts: 3
75+
window: 120s
7776
networks:
78-
- local
77+
- CoffeeChat
7978
ports:
8079
- "18080:18080"
8180
depends_on:
82-
- im_logic
83-
im_gate: # 网关服务
84-
container_name: im_gate
81+
- cim_logic
82+
cim_gate: # 网关服务
83+
container_name: cim_gate
8584
build:
8685
context: .
87-
dockerfile: app/im_gate/Dockerfile
86+
dockerfile: ./app/im_gate/Dockerfile
8887
volumes:
8988
- ./log/gate:/log
89+
deploy:
90+
restart_policy:
91+
condition: on-failure
92+
delay: 5s
93+
max_attempts: 3
94+
window: 120s
9095
networks:
91-
- local
96+
- CoffeeChat
9297
ports:
9398
- "8000:8000"
9499
depends_on:
95-
- im_logic
96-
im_logic: # 逻辑服务
97-
container_name: im_logic
100+
- cim_logic
101+
cim_logic: # 逻辑服务
102+
container_name: cim_logic
98103
build:
99104
context: .
100-
dockerfile: app/im_logic/Dockerfile
105+
dockerfile: ./app/im_logic/Dockerfile
101106
volumes:
102107
- ./log/logic:/log
103108
deploy:
@@ -107,9 +112,7 @@ services:
107112
max_attempts: 3
108113
window: 120s
109114
networks:
110-
- local
111-
# local:
112-
# - ipv4_address: 172.16.0.100
115+
- CoffeeChat
113116
depends_on:
114117
- mysql
115118
- redis
@@ -121,8 +124,12 @@ volumes: # 声明使用的数据卷,不使用宿主机目录,可以自行更
121124
cim_consul:
122125
driver: local
123126
# 为了简单,使用默认侨接网络 + DNS连接内部服务器方式
124-
# # 根据https://docs.docker.com/compose/networking/,docker compose默认创建了网络,但是创建自己的侨接网络更安全
125-
# #,另外一个Host主机网络只支持Linux,虽然性能更高
127+
# 根据https://docs.docker.com/compose/networking/,docker compose默认创建了网络,但是创建自己的侨接网络更安全
128+
# 另外一个Host主机网络只支持Linux,虽然性能更高
126129
networks:
127-
local:
128-
driver: bridge # 侨接网络
130+
CoffeeChat:
131+
driver: bridge # 侨接网络,此时需要使用host访问(service下面的服务名)
132+
ipam: # see: https://docs.docker.com/compose/compose-file/compose-file-v3/#network
133+
config:
134+
- subnet: 172.16.0.0/24
135+
gateway: 172.16.0.1

server/setup/mysql/init/init.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
-- CREATE USER 'luna'@'%' IDENTIFIED BY 'pwdluna';
2-
GRANT All privileges ON coffeechat.* TO 'cim'@'%' identified by 'ldMe$q2Xl9GKyUxj';
2+
GRANT All privileges ON coffeechat.* TO 'cim'@'%' identified by 'coffeechat2022';
33
flush privileges;

0 commit comments

Comments
 (0)