参考链接https://blog.csdn.net/qq_37288914/article/details/82895929
- 创建 MongoDB 数据卷
# docker volume create mongo_data_yapi
- 拉取镜像
# docker pull mongo
- 启动 MongoDB
# docker run -d --name mongo-yapi -v mongo_data_yapi:/data/db mongo
- 启动一个容器,复制/api/config.json到本地服务器
# docker run -d --name yapi --link mongo-yapi:mongo --workdir /api/vendors registry.cn-hangzhou.aliyuncs.com/anoy/yapi server/app.js
docker cp yapi:/api/config.json ./
- 建立映射目录
mkdir -p /usr/app/docker/yapi/conf/ (将config.json改好后放到该路径)
mkdir -p /usr/app/docker/yapi/log
官方默认的config.json是
{
"port": "3000",
"adminAccount": "admin@admin.com",
"db": {
"servername": "127.0.0.1",
"DATABASE": "yapi",
"port": 27017,
"user": "test1",
"pass": "test1",
"authSource": ""
},
"mail": {
"enable": true,
"host": "smtp.163.com",
"port": 465,
"from": "***@163.com",
"auth": {
"user": "***@163.com",
"pass": "*****"
}
}
}
- 初始化 Yapi 数据库索引及管理员账号
# docker run -it --rm --link mongo-yapi:mongo --entrypoint npm -v /usr/app/docker/yapi/conf/config.json:/api/config.json --workdir /api/vendors registry.cn-hangzhou.aliyuncs.com/anoy/yapi run install-serrrer
这里会输出管理员账号密码
- 运行yapi,通过管理员账号密码登录进去就可以了
docker run -d --name yapi --restart always --link mongo-yapi:mongo --workdir /api/vendors -p 8084:3000 \
-v /usr/app/docker/yapi/conf/config.json:/api/config.json \
-v /usr/app/docker/yapi/log:/api/log \
-v /etc/timezone:/etc/timezone \
-v /etc/localtime:/etc/localtime \
registry.cn-hangzhou.aliyuncs.com/anoy/yapi server/app.js
升级yapi
停止并删除旧版容器
docker rm -f yapi
获取最新镜像
docker pull registry.cn-hangzhou.aliyuncs.com/anoy/yapi
启动新容器
docker run -d --name yapi --restart always --link mongo-yapi:mongo --workdir /api/vendors -p 8084:3000 \
-v /usr/app/docker/yapi/conf/config.json:/api/config.json \
-v /usr/app/docker/yapi/log:/api/log \
-v /etc/timezone:/etc/timezone \
-v /etc/localtime:/etc/localtime \
registry.cn-hangzhou.aliyuncs.com/anoy/yapi server/app.js