1、首先已安装mongodb
2、
使用navicat连接数据库,使用以下命令创建数据库:
先use命令切换至yapi数据库。如果该库不存在,那么则会创建该数据库。
bash
use yapi;
创建用户,分配权限,下面会用到该用户和密码
bash
db.createUser({user:'yapi',pwd:'yapipwd',roles:[{role:'readWrite',db:'yapi'}]})
3、构建镜像
创建docker-yapi-bulid文件
html
FROM node:12-alpine
COPY repositories /etc/apk/repositories
RUN npm install -g yapi-cli --registry https://registry.npmmirror.com
EXPOSE 3000 9090
在docker-yapi-bulid同级目录下创建repositories文件
html
https://mirrors.aliyun.com/alpine/v3.6/main/
https://mirrors.aliyun.com/alpine/v3.6/community/
在docker-yapi-bulid同级目录下使用如下命令构建镜像
bash
docker build -f ./docker-yapi-bulid -t yapi:2.0 .
4、yapi-compose.yaml
html
version: '3.1'
services:
yapi:
image: yapi:2.0
container_name: yapi
command: "yapi server" #第一次启动使用
#command: "node /yapi/vendors/server/app.js" #后面启动使用
environment:
TZ: "Asia/Shanghai"
volumes:
- ./yapi:/yapi
ports:
- "9090:9090"
- "3000:3000"
restart: always
networks:
- yapi
networks:
yapi:
driver: bridge
5、启动
bash
docker-compose -f /opt/yh/yapi-compose.yaml up -d
6、安装
7、报错信息 还未解决
html
当前安装版本: 1.12.0
连接数据库成功!
开始下载平台文件压缩包...
http://registry.npm.taobao.org/yapi-vendor/download/yapi-vendor-1.12.0.tgz
部署文件完成,正在安装依赖库...
npm
ERR! code CERT_HAS_EXPIRED npm ERR! errno CERT_HAS_EXPIRED
npm ERR!
request to https://registry.npm.taobao.org/ajv failed, reason: certificate has expired
npm ERR! A complete log of this run can be found in: npm ERR! /root/.npm/_logs/2024-03-20T07_30_41_979Z-debug.log
依赖库安装完成,正在初始化数据库mongodb...
> yapi-vendor@1.12.0 install-server /yapi/vendors > node server/install.js
Error: internal/modules/cjs/loader.js:818 throw err; ^ Error: Cannot find module 'fs-extra' Require stack: - /yapi/vendors/server/install.js at Function.Module._resolveFilename (internal/modules/cjs/loader.js:815:15) at Function.Module._load (internal/modules/cjs/loader.js:667:27) at Module.require (internal/modules/cjs/loader.js:887:19) at require (internal/modules/cjs/helpers.js:74:18) at Object.<anonymous> (/yapi/vendors/server/install.js:1:12) at Module._compile (internal/modules/cjs/loader.js:999:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10) at Module.load (internal/modules/cjs/loader.js:863:32) at Function.Module._load (internal/modules/cjs/loader.js:708:14) at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12) { code: 'MODULE_NOT_FOUND', requireStack: [ '/yapi/vendors/server/install.js' ] }