頂尖 API 文檔管理工具 (YAPI)

? 使用 Docker 部署 YAPI

1、運行 MongoDB

# 創(chuàng)建存儲卷
docker volume create mongo-data

# 啟動 MongoDB
docker run -d \
  --name mongo-yapi \
  -v mongo-data:/data/db \
  -e MONGO_INITDB_ROOT_USERNAME=anoyi \
  -e MONGO_INITDB_ROOT_PASSWORD=anoyi.com \
  mongo

2、獲取 YAPI 鏡像,其他版本:阿里云鏡像倉庫

docker pull registry.cn-hangzhou.aliyuncs.com/anoyi/yapi

3、自定義配置文件 config.json

{
  "port": "3000",
  "adminAccount": "admin@anoyi.com",
  "timeout":120000,
  "db": {
    "servername": "mongo",
    "DATABASE": "yapi",
    "port": 27017,
    "user": "anoyi",
    "pass": "anoyi.com",
    "authSource": "admin"
  }
}

4、初始化 YAPI 數(shù)據(jù)庫索引及管理員賬號

docker run -it --rm \
  --link mongo-yapi:mongo \
  --entrypoint npm \
  --workdir /yapi/vendors \
  -v $PWD/config.json:/yapi/config.json \
  registry.cn-hangzhou.aliyuncs.com/anoyi/yapi \
  run install-server

5、啟動 Yapi 服務(wù)

docker run -d \
  --name yapi \
  --link mongo-yapi:mongo \
  --workdir /yapi/vendors \
  -p 3000:3000 \
  -v $PWD/config.json:/yapi/config.json \
  registry.cn-hangzhou.aliyuncs.com/anoyi/yapi \
  server/app.js

? 使用 YAPI

? 手動構(gòu)建 YAPI 鏡像

1、編輯 Dockerfile

FROM node:12-alpine as builder
WORKDIR /yapi
RUN apk add --no-cache wget python make
ENV VERSION=1.9.2
RUN wget https://github.com/YMFE/yapi/archive/v${VERSION}.zip
RUN unzip v${VERSION}.zip && mv yapi-${VERSION} vendors
RUN cd /yapi/vendors && cp config_example.json ../config.json && npm install --production --registry https://registry.npm.taobao.org

FROM node:12-alpine
MAINTAINER 545544032@qq.com
ENV TZ="Asia/Shanghai"
WORKDIR /yapi/vendors
COPY --from=builder /yapi/vendors /yapi/vendors
EXPOSE 3000
ENTRYPOINT ["node"]

注意將 Dockerfile 中的 VERSION 值修改為你需要構(gòu)建的 YAPI 版本。

2、構(gòu)建鏡像

docker build -t yapi .

? 其他相關(guān)操作

1、YAPI 升級

# 1、停止并刪除舊版容器
docker rm -f yapi

# 2、獲取最新鏡像
docker pull registry.cn-hangzhou.aliyuncs.com/anoyi/yapi

# 3、啟動新容器
docker run -d \
  --name yapi \
  --link mongo-yapi:mongo \
  --workdir /yapi \
  -p 3000:3000 \
  -v $PWD/config.json:/config.json \
  registry.cn-hangzhou.aliyuncs.com/anoyi/yapi \
  server/app.js

2、第三方插件安裝

稍微有一丟丟麻煩,看心情解決。。。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容