新手上路,小心开车
1. 安装mongo数据库
第一步:docker pull mongo 拉取mongo镜像;
第二步:启动mongo镜像
docker network create yapi_networkdocker run -d \-p 27017:27017 \--name mongodb \-e MONGO_INITDB_ROOT_USERNAME=yapi \-e MONGO_INITDB_ROOT_PASSWORD=test123456 \-e MONGO_INITDB_DATABASE=yapi \--net yapi_network \--restart always \-v /docker/mongo/config:/data/configdb/ \-v /docker/mongo/data:/data/db/ \mongo --auth
第三步:进入mongo容器,创建用户(yapi配置文件中的用户)
docker exec -it mongo bashmongo 127.0.0.1:27017use yapidb.createUser({user: 'yapi',pwd: 'yapi123456',roles: [{ role: "dbAdmin", db: "yapi" },{ role: "readWrite", db: "yapi" }]
});
2. 安装Yapi
第一步:拉取yapi镜像
第二步:编辑yapi配置文件
/docker/yapi/conf/config.json
{"port": "3000","adminAccount": "yapiadmin@163.com","timeout":120000,"db": {"servername": "mongodb", // mongo 容器名称"DATABASE": "yapi","port": 27017,"user": "yapi","pass": "yapi123456","authSource": "admin"},"mail": {"enable": true,"host": "smtp.163.com","port": 465,"from": "*","auth": {"user": "yapiadmin@163.com","pass": "yapiadminpassword"}}}
第三步:启动yapi容器
docker run -d \
--name yapi \
--link mongodb:mongo \
--restart always \
--net yapi_network \
-p 3000:3000 \
-v /docker/yapi/conf/config.json:/yapi/config.json \
yapipro/yapi:1.9.5 server/app.js