YAPI的数据存储在mongo中,所以在部署前我们需要先部署mongo;
为了省事,我将使用docker-compose一次部署,当然我们也可以使用外部的mongo!
一、初始化安装
1、创建所需文件夹:
mkdir -p /data/mongo mkdir -p /data/yapi
2、拉取github仓库部署脚本:
git clone https://github.com/Ryan-Miao/docker-yapi.git
3、将mongo-conf/文件夹放到我们创建好的/data/mongo目录下:
[root@ck103 docker-yapi]# cp -r mongo-conf/ /data/mongo/ # 可以修改下配置文件中的账号密码: [root@ck103 docker-yapi]# vim /data/mongo/mongo-conf/init-mongo.js db.createUser({ user: 'admin', pwd: 'admin123456', roles: [ { role: "root", db: "admin" } ] }); db.auth("admin", "admin123456"); db.createUser({ user: 'jiguiquan', pwd: '123456', roles: [ { role: "dbAdmin", db: "yapi" }, { role: "readWrite", db: "yapi" } ] });
4、修改docker-compose.yml:
# Use root/example as user/password credentials version: '3.1' services: mongo: image: mongo:4 restart: always environment: MONGO_INITDB_ROOT_USERNAME: root MONGO_INITDB_ROOT_PASSWORD: 123456 MONGO_INITDB_DATABASE: yapi volumes: - /data/mongo/mongo-conf:/docker-entrypoint-initdb.d - /data/mongo/etc:/etc/mongo - /data/mongo/data/db:/data/db ports: - 27017:27017 healthcheck: test: ["CMD", "netstat -anp | grep 27017"] interval: 2m timeout: 10s retries: 3 yapi: build: context: ./ dockerfile: Dockerfile image: yapi # 第一次启动使用 command: "yapi server" # 之后使用下面的命令 # command: "node /my-yapi/vendors/server/app.js" volumes: - /data/yapi:/my-yapi ports: - 9090:9090 - 3000:3000 depends_on: - mongo
5、执行docker-compose:
docker-compose up
6、查看服务:
[root@ck103 docker-yapi]# docker-compose ps Name Command State Ports ----------------------------------------------------------------------------------------------------------------------------- docker-yapi_mongo_1 docker-entrypoint.sh mongod Up (health: starting) 0.0.0.0:27017->27017/tcp docker-yapi_yapi_1 docker-entrypoint.sh yapi ... Up 0.0.0.0:3000->3000/tcp, 0.0.0.0:9090->9090/tcp
二、配置项目并重启
1、打开http://ip:9090安装页面:
按如下截图选择自己想要安装的版本,和配置:
2、部署完成:
账号:jiguiquan@163.com
密码:ymfe.org
3、部署完毕后, 修改docker-compose.yml并重启服务:
...... services: yapi: build: context: ./ dockerfile: Dockerfile image: yapi # 第一次启动使用 # command: "yapi server" # 之后使用下面的命令 command: "node /my-yapi/vendors/server/app.js" volumes: - /data/yapi:/my-yapi ports: - 9090:9090 - 3000:3000 depends_on: - mongo
重启服务:
docker-compose up -d
4、重启完成后,可以通过 http://ip:3000 访问yapi的正式页面:
使用上面的账号密码,登录系统即可:
愉快的玩耍吧!