docker 搭建 yapi 服务

2023-03-16  本文已影响0人  ag4kd

下载 docker-yapi

git clone https://github.com/Ryan-Miao/docker-yapi

安装 MongoDB

查看相关配置

# Use root/example as user/password credentials
version: '3.1'

services:
#  mongo:
#    image: mongo:4
#    restart: always
#    environment:
#      MONGO_INITDB_ROOT_USERNAME: root
#      MONGO_INITDB_ROOT_PASSWORD: example
#      MONGO_INITDB_DATABASE: yapi
#    volumes:
#      - ./mongo-conf:/docker-entrypoint-initdb.d
#      - ./mongo/etc:/etc/mongo
#      - ./mongo/data/db:/data/db
#    ports:
#      - 27017:27017
#    healthcheck:
#      test: ["CMD", "netstat -anp | grep 27017"]
#      interval: 2m
#      timeout: 10s
#      retries: 3
  yapi:
    build:
      context: ./
      dockerfile: Dockerfile
    image: yapi
    # 第一次启动使用
    # command: "yapi server"
    # 之后使用下面的命令
    command: "node /my-yapi/vendors/server/app.js"
    volumes:
      - ./my-yapi:/my-yapi
    ports:
      - 9090:9090
      - 3000:3000
#    depends_on:
#      - mongo

数据库设置

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,我使用官方的方式启动的 MongoDB,连接不上,自己装了一个 MongoDB,然后按照项目中的脚本,执行一下数据库相关的操作:

version: '3.1'

services:
  yapi:
    build:
      context: ./
      dockerfile: Dockerfile
    image: yapi
    command: "yapi server"
    # 之后使用下面的命令
    # command: "node /my-yapi/vendors/server/app.js"
    volumes: 
        - ./my-yapi:/my-yapi
    ports: 
      - 9090:9090
      - 3000:3000
version: '3.1'

services:
  yapi:
    build:
      context: ./
      dockerfile: Dockerfile
    image: yapi
    command: "yapi server"
    # 之后使用下面的命令
    # command: "node /my-yapi/vendors/server/app.js"
    volumes: 
        - ./my-yapi:/my-yapi
    ports: 
      - 9090:9090
      - 3000:3000
上一篇 下一篇

猜你喜欢

热点阅读