一、总体目录结构(觉得麻烦的同学可以直接去仓库拉取:yapi-data: 构建yapi相关数据)
|-- docker-compose-yapi.yml
`-- yapi --目录
|-- config.json
|-- start.sh
`-- vendors --目录
二、创建docker-compose-yapi.yml文件
version: '2'
services:
mongo:
image: mongo
container_name: mongo
restart: always
volumes:
- ./mongo/configdb:/data/configdb
- ./mongo/db:/data/db
ports:
- 27017:27017
yapi:
image: node:12.22.7
container_name: yapi
restart: always
working_dir: /etc/yapi
volumes:
- ./yapi:/etc/yapi
links:
- mongo
depends_on:
- mongo
ports:
- 3000:3000
command:
bash start.sh
?三、创建yapi配置文件config.json
{
"port": "3000",
"adminAccount": "yapi@yapi.com",
"timeout":120000,
"db": {
"servername": "mongo",
"DATABASE": "yapi",
"port": 27017
}
}
四、创建yapi启动脚本start.sh(记得这里 chmod +x start.sh 添加执行权限哦 !)
#!/bin/bash
INIT_FILE_NAME="init.lock"
PROGRAM_CATALOG="vendors"
# whether exist init file.
if [[ -f ${INIT_FILE_NAME} ]]; then
echo -e "again start ~"
cd ${PROGRAM_CATALOG}
npm install --registry=https://registry.npm.taobao.org
else
echo -e "init start ~"
cd ${PROGRAM_CATALOG}
npm install --registry=https://registry.npm.taobao.org
# init admin user.
npm run install-server
fi
# start before install.
node server/app.js
五、在yapi下运行,vendors下载
如果没有安装git同学请运行,安装同学可以忽略 yum -y install git
# 从git获取文件
git clone https://github.com/YMFE/yapi.git vendors && rm -rf vendors/package-lock.json
如果上面拉取慢,可以使用作者从github导入gitee的仓库
git clone https://gitee.com/zhijian0128/yapi.git vendors && rm -rf vendors/package-lock.json
?六、开始构建
docker-compose -f docker-compose-yapi.yml up -d
七、查看是否成功
# 使用命令查看容器日志,构建成功可以看到下面图片信息,你就可以使用本机ip访问了
docker logs yapi
2.初始信息,账户名在上面config.json中adminAccount,可以在构建前修改,构建后可以在mongodb修改
账号名:yapi@yapi.com,密码:ymfe.org
?八、如果需要更新最新版本,可以在yapi目录下运行,程序升级
# 升级命令,如果这里拉取仓库过慢,建议大家从github导入到码云,替换下面地址即可
rm -rf vendors && git clone https://github.com/YMFE/yapi.git vendors && rm -rf vendors/package-lock.json && docker restart yapi
|