docker-compose部署yapi

以docker-compose方式部署yapi。最新版本:1.9.2


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" }
    ]});

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

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/yapinetworks:
  yapi:
    driver: bridge

  • 部署:
mkdir -p /data/yapi/{mongo,yapi}docker-compose up --build

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

docker-compose部署yapi

docker-compose部署yapi

使用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/yapinetworks:
  yapi:
    driver: bridge

docker-compose up -d

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

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

docker-compose部署yapi

docker-compose部署yapi

至此,以docker-compose方式部署yapi完成。已存放至个人github:docker-compose


上一篇:linux单机版mongo安装(带密码验证)


下一篇:mongo从应用程序连接副本集