1.编辑Dockerfile
config.json修改为自己的环境,建议只改db部分,依赖mongodb数据库;官网文档里说支持mongodb集群方式,但我没成功们只能配置为单节点的方式;adminAccount也不建议在配置文件里改,应该有格式限制。
FROM node:18 as builder
WORKDIR /yapi
ENV VERSION=1.12.0
RUN wget https://github.com/YMFE/yapi/archive/v${VERSION}.zip
RUN unzip v${VERSION}.zip && mv yapi-${VERSION} vendors
RUN cat <<eof > config.json
{
"port": "3000",
"adminAccount": "admin@admin.com",
"timeout":120000,
"db": {
"servername": "192.16.2.15",
"DATABASE": "yapidb",
"port": 27017,
"user": "yapi",
"pass": "yapiPwd",
"authSource": ""
},
"mail": {
"enable": true,
"host": "smtp.163.com",
"port": 465,
"from": "***@163.com",
"auth": {
"user": "***@163.com",
"pass": "*****"
}
}
}
eof
RUN cd /yapi/vendors && rm -rf package-lock.json config_example.json && npm install --omit=dev --registry https://registry.npm.taobao.org --legacy-peer-deps
FROM node:16-alpine as runner
ENV TZ="Asia/Shanghai"
WORKDIR /yapi/vendors
COPY --from=builder /yapi /yapi
EXPOSE 3000
CMD ["node","server/app.js"]
2.构建镜像
docker build -t yapi:v1.12.0 .
3.初始化数据库索引和管理员账号
默认管理员账号:“admin@admin.com”,密码:“ymfe.org”,执行成功会有显示
docker run -it --rm --name yapi yapi:v1.12.0 npm run install-server
4.启动yapi服务
docker run -d --name yapi -p 7070:3000 yapi:v1.12.0