在 Ubuntu 18.04 上 docker 部署 easymock

安装环境

Ubuntu 18.04.4

jiangzl@zhaoyang-k21:~$ sudo lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.4 LTS
Release:        18.04
Codename:       bionic

apt 1.6.12

jiangzl@zhaoyang-k21:~$ sudo apt -v
apt 1.6.12 (amd64)

Dock-CE 19.03.8

jiangzl@zhaoyang-k21:~$ sudo docker version
Client: Docker Engine - Community
 Version:           19.03.8
 API version:       1.40
 Go version:        go1.12.17
 Git commit:        afacb8b7f0
 Built:             Wed Mar 11 01:25:46 2020
 OS/Arch:           linux/amd64
 Experimental:      false
Server: Docker Engine - Community
 Engine:
  Version:          19.03.8
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.12.17
  Git commit:       afacb8b7f0
  Built:            Wed Mar 11 01:24:19 2020
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.2.13
  GitCommit:        7ad184331fa3e55e52b890ea95e65ba581ae3429
 runc:
  Version:          1.0.0-rc10
  GitCommit:        dc9208a3303feef5b3839f4323d9beb36df0a9dd
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683

安装准备

1、如果你还不知道什么是 easymock

可以去 easymock 官网看一下,以及他们的开源仓库。简单来说,easymock 干的主要事情就是模拟接口,做前后端分享式开发的一定不陌生。在后端开发好接口给前端之前,可以使用 easymock 根据定义好的接口数量与规范来定义 easymock 的模拟接口,模拟数据。这样,前端就能像一个正常调用后端接口一样使用,只是接口数据是模拟的。只要后端提供了真实接口,前端把 easymock 的 API 链接替换成后端 API 链接就完成了,非常地方便。

https://www.easy-mock.com/
https://github.com/easymock/easymock

注:easymock 不能实现多个接口之间的数据联动,比如 A 接口的 response 中的字段1作为 B 接口的参数。但可以对不同的数据输入进行逻辑判断并返回。

2、apt update

jiangzl@zhaoyang-k21:~$ sudo apt update
[sudo] password for jiangzl: 
Hit:1 http://dl.google.com/linux/chrome/deb stable InRelease
Hit:2 http://linux.teamviewer.com/deb stable InRelease                                                                                                               
Hit:3 http://cn.archive.ubuntu.com/ubuntu bionic InRelease                                                                                                           
Get:4 http://security.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]                                                   
Get:5 http://cn.archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]                                
Hit:6 https://download.docker.com/linux/ubuntu bionic InRelease                                                        
Get:7 http://cn.archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB]                                         
Fetched 252 kB in 3s (92.3 kB/s)   
Reading package lists... Done
Building dependency tree       
Reading state information... Done
12 packages can be upgraded. Run 'apt list --upgradable' to see them.

安装步骤

1、安装 docker-ce

jiangzl@zhaoyang-k21:~$ sudo apt install docker

参考:https://docs.docker.com/engine/install/ubuntu/

2、安装 docker-compse

参考:https://docs.docker.com/compose/install/

 

相关配置

1、配置 docker 镜像

在 /etc/docker 下新建 daemon.json

jiangzl@zhaoyang-k21:/data/easy-mock$ cd /etc/docker
jiangzl@zhaoyang-k21:/data/easy-mock$ vim daemon.json

并填写如下内容(配置网易云 docker 镜像)

{        
    "registry-mirrors": ["http://hub-mirror.c.163.com"]
}

2、配置 docker-compse.yml

在 /data 下新建一个 easy-mock 的目录

jiangzl@zhaoyang-k21:~$ cd /data
jiangzl@zhaoyang-k21:/data$ 
jiangzl@zhaoyang-k21:/data$ 
jiangzl@zhaoyang-k21:/data$ sudo mkdir easy-mock
jiangzl@zhaoyang-k21:/data$ sudo chown -R jiangzl.jiangzl easy-mock/

注:/data 目录可以换成你服务器的其他可用目录(如果此处 /data 换为其他目录,则下方的 docker-compose.yml 中的 /data/easy-mock 对应换成 /YOUR_DIR/easy-mock 即)。jiangzl.jiangzl 请换成当前用户。

在 /data/easy-mock 下新建一个 docker-compose.yml 文件

jiangzl@zhaoyang-k21:/data/easy-mock$ pwd
/data/easy-mock
jiangzl@zhaoyang-k21:/data/easy-mock$ vi docker-compose.yml

写入如下内容

version: '3'
 
services:
  mongodb:
    image: mongo:3.4
    volumes:
      - './data/db:/data/easy-mock/data/db'
    networks:
      - easy-mock
    restart: always
 
  redis:
    image: redis:4.0.6
    command: redis-server --appendonly yes
    volumes:
      - './data/redis:/data/easy-mock/data/redis'
    networks:
      - easy-mock
    restart: always
 
  web:
    image: easymock/easymock:1.6.0
    command: /bin/bash -c "npm start"
    ports:
      - 7300:7300
    volumes:
      - './logs:/data/easy-mock/logs'
      - './production.json:/data/easy-mock/production.json'
    networks:
      - easy-mock
    restart: always
 
networks:
  easy-mock:

3、配置 production.json

在 /data/easy-mock 目录下新建 production.json 文件

jiangzl@zhaoyang-k21:/data/easy-mock$ pwd
/data/easy-mock
jiangzl@zhaoyang-k21:/data/easy-mock$ 
jiangzl@zhaoyang-k21:/data/easy-mock$ vim production.json

并填写如下内容:

  "port": 7300,
  "host": "0.0.0.0",
  "pageSize": 30,
  "proxy": false,
  "db": "mongodb://mongodb/easy-mock",
  "unsplashClientId": "",
  "redis": {
    "keyPrefix": "[Easy Mock]",
    "port": 6379,
    "host": "redis",
    "password": "",
    "db": 0
  },
  "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
    }
  },
  "ldap": {
    "server": "",
    "bindDN": "",
    "password": "",
    "filter": {
      "base": "",
      "attributeName": ""
    }
  },
  "fe": {
    "copyright": "",
    "storageNamespace": "easy-mock_",
    "timeout": 25000,
    "publicPath": "/dist/"
  }
}

简单运行

进入 /data/easy-mock 目录,运行如下命令

jiangzl@zhaoyang-k21:/data/easy-mock$ sudo docker-compose up
Creating network "easy-mock_easy-mock" with the default driver
Pulling mongodb (mongo:3.4)...
3.4: Pulling from library/mongo
0a01a72a686c: Downloading [=========>                                         ]  8.666MB/44.15MB
cc899a5544da: Download complete
19197c550755: Download complete
716d454e56b6: Download complete
0793d4ab2500: Download complete
df33e33466d0: Download complete
3b2d76901480: Download complete
df04584b8696: Download complete
44374faf31f3: Download complete
fa872588a313: Download complete
dc7c21f1f450: Downloading [==>                                                ]   6.97MB/119.7MB
f8ec26dc5fff: Download complete
339b4d52030e: Download complete
ec82d062b203: Download complete

等待 docker 拉取镜像,完成后即完成安装。

安装验证

在浏览器输入 http://ip:7300 如出现如下界面,表示安装成功。

点击 OK,然后点击 “开始吧”

注册一个账号,有账号则直接登录。

如果输入的用户不存在,点击登录时会有一个对话框弹出,提示会注册用户,且密码就是你输入的未经过二次确认的密码。让你保管好,忘了或者输入错误均无法找回(…感觉这是上个世纪的产品逻辑,不管了,能用就行!)

然后点击 “确定”,提示注册成功,进入界面

至此,整个 easy-mock 安装结束。

https://docs.docker.com/compose/install/

https://blog.csdn.net/chinesesword/article/details/104525008

You may also like...

发表评论

电子邮件地址不会被公开。 必填项已用*标注

%d 博主赞过: