Yapi 1.9.2 部署手册

本文是以docker-compose方式部署yapi
版本:1.9.2

Dockerfile

FROM node:12-alpine

COPY repositories /etc/apk/repositories

RUN npm install -g yapi-cli --registry https://registry.npm.taobao.org

EXPOSE 3000 9090

repositories

https://mirrors.aliyun.com/alpine/v3.6/main/

https://mirrors.aliyun.com/alpine/v3.6/community/

init-mongo.js

db.createUser({ user: 'admin', pwd: 'admin123456', roles: [ { role: "root", db: "admin" } ] });

db.auth("admin", "admin123456");

db.createUser({
    user: 'yapi',
    pwd: 'yapi123456',
    roles: [
        { role: "dbAdmin", db: "yapi" },
        { role: "readWrite", db: "yapi" }
    ]
});

docker-compose.yml

version: '3.7'

services:
  mongo:
    container_name: mongo
    image: mongo:4
    ports:
      - "27017:27017"
    volumes:
      - type: volume
        source: mongo
        target: /data/db
    environment:
      MONGO_INITDB_ROOT_USERNAME: root
      MONGO_INITDB_ROOT_PASSWORD: example
      MONGO_INITDB_DATABASE: yapi
    restart: always
    volumes:
      - type: bind
        source: ./init-mongo.js
        target: /docker-entrypoint-initdb.d/init-mongo.js
        read_only: true
      - type: volume
        source: mongo
        target: /data/db
    networks:
      - yapi

  yapi:
    depends_on:
      - mongo
    build:
      context: ./
    container_name: yapi
    image: yapi
    command: "yapi server"              #第一次启动使用
    #command: "node /yapi/vendors/server/app.js"             #后面启动使用
    ports: 
      - "9090:9090"
      - "3000:3000"
    restart: always
    volumes:
      - type: volume
        source: yapi
        target: /yapi
    networks:
      - yapi


volumes:
  mongo:
    driver: local
    driver_opts:
      type: none
      o: bind
      device: /data/yapi/mongo
  yapi:
    driver: local
    driver_opts:
      type: none
      o: bind
      device: /data/yapi/yapi

networks:
  yapi:
    driver: bridge

部署

mkdir -p /data/yapi/{mongo,yapi}

docker-compose up --build

打开 ip:9090 ,输入相应的配置和点击开始部署,完成整个网站的部署
Yapi 1.9.2 部署手册

部署完成后,使用Ctrl + C退出,重新修改 docker-compose.yaml

version: '3.7'

services:
  mongo:
    container_name: mongo
    image: mongo:4
    ports:
      - "27017:27017"
    volumes:
      - type: volume
        source: mongo
        target: /data/db
    environment:
      MONGO_INITDB_ROOT_USERNAME: root
      MONGO_INITDB_ROOT_PASSWORD: example
      MONGO_INITDB_DATABASE: yapi
    restart: always
    volumes:
      - type: bind
        source: ./init-mongo.js
        target: /docker-entrypoint-initdb.d/init-mongo.js
        read_only: true
      - type: volume
        source: mongo
        target: /data/db
    networks:
      - yapi

  yapi:
    depends_on:
      - mongo
    build:
      context: ./
    container_name: yapi
    image: yapi
    #command: "yapi server"              #第一次启动使用
    command: "node /yapi/vendors/server/app.js"             #后面启动使用
    ports: 
      - "9090:9090"
      - "3000:3000"
    restart: always
    volumes:
      - type: volume
        source: yapi
        target: /yapi
    networks:
      - yapi


volumes:
  mongo:
    driver: local
    driver_opts:
      type: none
      o: bind
      device: /data/yapi/mongo
  yapi:
    driver: local
    driver_opts:
      type: none
      o: bind
      device: /data/yapi/yapi

networks:
  yapi:
    driver: bridge

使用如下命令:

docker-compose up -d

docker-compose ps
Name               Command               State                                    Ports                                  
-------------------------------------------------------------------------------------------------------------------------
mongo   docker-entrypoint.sh mongod      Up      0.0.0.0:27017->27017/tcp,:::27017->27017/tcp                            
yapi    docker-entrypoint.sh node  ...   Up      0.0.0.0:3000->3000/tcp,:::3000->3000/tcp,                               
                                                 0.0.0.0:9090->9090/tcp,:::9090->9090/tcp   

打开ip:3000,账号/密码:admin@admin.com/ymfe.org

Yapi 1.9.2 部署手册

上一篇:Win10 各种端口占用问题的解决办法


下一篇:git简易教程