以docker-compose方式部署yapi。最新版本:1.9.2html
repositoriesnode
https://mirrors.aliyun.com/alpine/v3.6/main/ https://mirrors.aliyun.com/alpine/v3.6/community/
init-mongo.jsgit
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" } ]});
Dockerfilegithub
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.ymldocker
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
,輸入相應的配置和點擊開始部署,完成整個網站的部署。npm
使用Ctrl + C
退出,從新修改 docker-compose.yaml
api
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
。app
至此,以docker-compose方式部署yapi完成。已存放至我的github:docker-composetcp