
? 使用 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
- 訪問: http://localhost:3000
- 登錄賬號:
admin@anoyi.com - 密碼:
ymfe.org

? 手動構(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、第三方插件安裝
稍微有一丟丟麻煩,看心情解決。。。