如何在雲服務器上使用Docker部署easy-mock

部署Easy-mock

安裝Docker

Ubuntu下安裝Dockerlinux

安裝Docker-compose

Ubuntu下安裝docker-composeweb

使用Docker部署

  1. Easy-Mock Docker鏡像
  2. 根聽說明,修改docker-compose.yml文件以下:
version: "3.3"
services:
mongodb:
image: mongo:5.0
volumes:
- type: bind
source: /home/yourname/data/mongodb/easymock # 數據庫文件存放地址,根據須要修改成本地地址
target: /data/db
redis:
image: redis:4.0.6
command: redis-server --appendonly yes
volumes:
- type: bind
source: /home/yourname/data/redis/easymock # redis 數據文件存放地址,根據須要修改成本地地址
target: /data
web:
image: easymock/easymock:1.6.0
command: /bin/bash -c "npm start"
links:
- mongodb:mongodb
ports:
- 7300:7300
volumes:
- type: bind 
source: /home/yourname/easy-mock/logs # 日誌地址,根據須要修改成本地地址
target: /home/easy-mock/easy-mock/logs
- type: bind
source: /home/yourname/easy-mock/config/local.json # 配置地址,請使用本地配置地址替換
target: /home/easy-mock/easy-mock/config/production.json
  1. 修改local.json文件

去掉"db"和"redis"配置redis

{
"port": 7300,
"host": "0.0.0.0",
"pageSize": 30,
"proxy": false, 
"unsplashClientId": "", 
"blackList": {
"projects": [],
"ips": []
},
"rateLimit": {
"max": 1000,
"duration": 1000
},
"jwt": {
"expire": "14 days",
"secret": "shared-secret"
},
"upload": {
"types": [
".jpg",
".jpeg",
".png",
".gif",
".json",
".yml",
".yaml"
],
"size": 5242880,
"dir": "../public/upload",
"expire": {
"types": [
".json",
".yml",
".yaml"
],
"day": -1
}
},
"fe": {
"copyright": "",
"storageNamespace": "easy-mock_",
"timeout": 25000,
"publicPath": "/dist/"
}
}
  1. 將docker-compose.yml和local.json放到服務器文件夾中
  2. 運行 docker-compose up -d
  3. 運行 sudo docker ps查看是否已運行

阿里雲上設置安全規則

若是easy-mock的端口設置爲7300,到阿里雲服務器管理列表中,添加安全規則,採用"tcp",端口號設爲"7300/7300",其餘按照教程設置。mongodb

在網頁上輸入IP:7300便可訪問easy-mockdocker

報錯信息處理

  1. 問題一:

Couldn't connect to Docker daemon at http+docker://localunixsocket - is it running?數據庫

答案:須要將當前用戶加入到docker用戶組
sudo gpasswd -a ${USER} dockernpm

網上教程json

  1. 問題二:找不到指定路徑

答案:須要建立「/data/mongodb/easymock」等路徑。ubuntu

相關文章
相關標籤/搜索