docker-compose用法3.0
最后更新于:2022-04-02 07:10:40
# 微服务Docker镜像制作 3.0
*环境:windows+idea+docker*
>[info] version: jeecg 3.0.0 (含之前版本)
docker脚本在:`jeecg-cloud-module/docker-compose.yml`,本文旨在如何通过该文件启动微服务项目
## JeecgBoot 微服务后台 镜像制作
- 1.修改jeecg-boot-parent的pom文件配置nacos服务地址 **(非常重要)**
```
jeecg-boot-nacos:8848
```

>[warning] 注意:不改这个,会导致nacos连不上
- 2.修改jeecg-boot-module-system微服务打包配置(jeecg-boot-module-system/pom.xml)
此步骤很重要,不然会启动报错 No qualifying bean of type org.jeecg.common.api.CommonAPI
```
skip属性改为true
```

- 3.项目打包 `install`

看到执行成功

- 4.修改本地hosts文件
```
127.0.0.1 jeecg-boot-redis
127.0.0.1 jeecg-boot-mysql
127.0.0.1 jeecg-boot-nacos
127.0.0.1 jeecg-boot-gateway
127.0.0.1 jeecg-boot-system
127.0.0.1 jeecg-boot-rabbitmq
127.0.0.1 jeecg-boot-xxljob
```
- 5.进入jeecg-cloud-module目录下,执行命令 `docker-compose up -d`


- 6.按顺序手工重启镜像
由于暂时还未做容器编排,mysql的初始化慢会导致 nacos、system、gateway启动失败或报错,所以需要手工重启下镜像,请按照下面的步骤操作。
[1]. 先确认mysql容器的数据库初始化完成,查看mysql容器日志或者等待1分钟

[2]. mysql完成后,先重启nacos
访问: http://localhost:8848/nacos

[3].再重启system(会自动重启)
[4].最后重启gateway

- 7.验证后台服务,访问swagger文档
http://localhost:9999/doc.html

常见问题
1.swagger文档实例访问不到
解决: 等system启动成功后,重启gateway。

2.mysql、redis容器创建失败
解决:如果是本地的话,确认下是否有已启动的mysql、redis,端口冲突了,关闭本地服务
3.如果一开始配置错误,执行过命令,需要手工删除下生成过的镜像(不然始终用的是老的镜像文件)

*****
## 前端ant-design-vue-jeecg 镜像制作
代码路径:https://github.com/zhangdaiscott/jeecg-boot/tree/master/ant-design-vue-jeecg
### 1. 修改前端项目的后台域名
.env.production
~~~
NODE_ENV=production
VUE_APP_API_BASE_URL=https://bootapi.jeecg.com
VUE_APP_CAS_BASE_URL=http://localhost:8888/cas
VUE_APP_ONLINE_BASE_URL=http://fileview.jeecg.com/onlinePreview
~~~
### 2. 先进入打包前端项目
yarn run build
### 3. 构建镜像
docker build -t nginx:jeecgboot .
### 4. 启动镜像
docker run --name jeecg-boot-nginx -p 80:80 -d nginx:jeecgboot
### 5. 访问前台项目
http://localhost:80
';