![a62dc4197aa3d2011b3f76d250f33eb9.gif](https://i-blog.csdnimg.cn/blog_migrate/9c1cea9ce786610ed3a0050d98c58edb.gif)
前言:我们选择在linux系统中完成此项任务,使用的是centos7.6
安装Docker(提示:已安装的小伙伴可以忽略此步骤)
yum 包更新到最新:
sudo yum -y update
安装需要的软件包, yum-util 提供 yum-config-manager 功能,另外两个是devicemapper 驱动依赖的
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
设置 yum 源为阿里云
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
安装 docker
sudo yum install docker-ce
安装后查看 docker 版本
docker -v
![2688804ee1b7d60ff8325c530f4f80c0.png](https://i-blog.csdnimg.cn/blog_migrate/7b57653f5f077f874a13e27f190355ba.png)
![14783a602735d82fe312d23c56077131.png](https://i-blog.csdnimg.cn/blog_migrate/f9e260b603e85b3b942e2c09ba5620c5.jpeg)
国内从 DockerHub 拉取镜像有时会遇到困难,此时可以配置镜像加速器。
使用阿里云镜像加速器首先进入阿里云的docker库:https://www.aliyun.com/product/kubernetes?spm=5176.10695662.1362911.1.3cab795d6uoX0P
注册或登录账号,并进入控制台管理
选择镜像加速器选项
![2688804ee1b7d60ff8325c530f4f80c0.png](https://i-blog.csdnimg.cn/blog_migrate/7b57653f5f077f874a13e27f190355ba.png)
![e2727db635e346ef2ae280b082265f5f.png](https://i-blog.csdnimg.cn/blog_migrate/0396faa0ca8df4abdabb244f3bb5a198.jpeg)
进入到镜像加速器选项,可以看到你的加速器地址,可以根据操作文档步骤进行配置
先创建文件夹,然后编辑文件daemon.json(没有此文件使用touch创建文件)
sudo mkdir -p /etc/dockertouch /etc/docker/daemon.jsonvi /etc/docker/daemon.json
![2688804ee1b7d60ff8325c530f4f80c0.png](https://i-blog.csdnimg.cn/blog_migrate/7b57653f5f077f874a13e27f190355ba.png)
![ea30c18481584420c6950eb7bc57a35c.png](https://i-blog.csdnimg.cn/blog_migrate/1534b2e8a60531f7e9f429da02bf8529.jpeg)
在该文件中输入如下内容,打码的部分为你自己的阿里加速器地址
{"registry-mirrors": ["https://xxxxx.xxxxx.aliyuncs.com"]}
编辑保存后,需要重启,输入如下命令
sudo systemctl daemon-reload #重启加速器sudo systemctl restart docker #重启docker
关闭防火墙
systemctl stop firewalld
安装镜像
MongoDB 安装
docker pull mongo
![2688804ee1b7d60ff8325c530f4f80c0.png](https://i-blog.csdnimg.cn/blog_migrate/7b57653f5f077f874a13e27f190355ba.png)
![e612aa540f468608350b38eec9485575.png](https://i-blog.csdnimg.cn/blog_migrate/1a0bba2bedaae72c54a8f378511e5a00.jpeg)
Redis 安装
docker pull redis
![2688804ee1b7d60ff8325c530f4f80c0.png](https://i-blog.csdnimg.cn/blog_migrate/7b57653f5f077f874a13e27f190355ba.png)
![9b1aa2d9e53fa94ec89b50890bbe4d29.png](https://i-blog.csdnimg.cn/blog_migrate/33f829ac80e3fadc7cc358e8c1b95a6b.jpeg)
拉取 easymock
docker pull blackcater/easy‐mock
![2688804ee1b7d60ff8325c530f4f80c0.png](https://i-blog.csdnimg.cn/blog_migrate/7b57653f5f077f874a13e27f190355ba.png)
![f9f7a63354a733cf3a516b8966cf2a77.png](https://i-blog.csdnimg.cn/blog_migrate/aceed91a7e7dc9337a16a373e2ebeabc.jpeg)
启动 mongo
docker run ‐d ‐p 27017:27017 ‐v /usr/local/share/mongo/data/:/data ‐‐name mongo ‐‐restart=always mongo
![2688804ee1b7d60ff8325c530f4f80c0.png](https://i-blog.csdnimg.cn/blog_migrate/7b57653f5f077f874a13e27f190355ba.png)
![8c194031e98583693f3f4588ada9d651.png](https://i-blog.csdnimg.cn/blog_migrate/e8ad38f37eb5c719c6a45a352adc60bb.jpeg)
进入容器,创建数据库
docker exec ‐it mongo bashmongouse easy-mock
![2688804ee1b7d60ff8325c530f4f80c0.png](https://i-blog.csdnimg.cn/blog_migrate/7b57653f5f077f874a13e27f190355ba.png)
![1ea54c1c907d16033558fdc1f1f1e458.png](https://i-blog.csdnimg.cn/blog_migrate/2246c180229eb7b78b36ba8e91bff108.jpeg)
启动 redis
docker run -p 6379:6379 --name redis -v /home/users/docker/redis/data:/data -d redis redis-server --appendonly yes
![2688804ee1b7d60ff8325c530f4f80c0.png](https://i-blog.csdnimg.cn/blog_migrate/7b57653f5f077f874a13e27f190355ba.png)
![10a5f6c0a5bd74718f4f23be75565a03.png](https://i-blog.csdnimg.cn/blog_migrate/4f2d0d60100af59c73bc76311fa413a6.jpeg)
在/usr/local/share/mock/config/映射目录下创建 default.json 和 local.json 文件,用于配置easymock:配置如下
![2688804ee1b7d60ff8325c530f4f80c0.png](https://i-blog.csdnimg.cn/blog_migrate/7b57653f5f077f874a13e27f190355ba.png)
![ee9834cd7ad365cefffd79ba5c014bf3.png](https://i-blog.csdnimg.cn/blog_migrate/f09b8ddd5c563e481105e078435c0d02.jpeg)
default.json
{ "port": 7300, "host": "0.0.0.0", "pageSize": 30, "proxy": false, "db": "mongodb://mongo:27017/easy-mock", "unsplashClientId": "", "redis": { "keyPrefix": "[Easy Mock]", "port": 6379, "host": "localhost", "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/" } }
local.json
{ "port": 7300, "host": "0.0.0.0", "pageSize": 30, "proxy": false, "db": "mongodb://172.17.0.1:27017/easy-mock", "unsplashClientId": "", "redis": { "port": 6379, "host": "172.17.0.1" }, "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/" }}
启动 easymock 容器
docker run ‐d ‐p 7300:7300 ‐‐link mongo:mongo ‐v /usr/local/share/mock/config/:/easy‐mock/config ‐‐name easymock blackcater/easy‐mock
![2688804ee1b7d60ff8325c530f4f80c0.png](https://i-blog.csdnimg.cn/blog_migrate/7b57653f5f077f874a13e27f190355ba.png)
![337159a771d4f37e8d6db26b72fae00f.png](https://i-blog.csdnimg.cn/blog_migrate/89d924717c902ff44ebc0e227453c961.jpeg)
进入easymock容器中并运行 easymock 项目
docker exec ‐it easymock bashpm2 start app.js
![2688804ee1b7d60ff8325c530f4f80c0.png](https://i-blog.csdnimg.cn/blog_migrate/7b57653f5f077f874a13e27f190355ba.png)
![d0f13d6f2cec2b3e46fcbdbf4cb66652.png](https://i-blog.csdnimg.cn/blog_migrate/826131d1738e48ef3fa6e4bcc148a3a7.jpeg)
浏览器地址输入:192.168.232.134:7300
![2688804ee1b7d60ff8325c530f4f80c0.png](https://i-blog.csdnimg.cn/blog_migrate/7b57653f5f077f874a13e27f190355ba.png)
![56895bf3be1c8080179ff8578933b8d3.png](https://i-blog.csdnimg.cn/blog_migrate/1aed5bf05aa2cab0dd3694e847acaf7a.jpeg)
![8a0ec39fa0ee7ed68a94dcf1004a17e6.png](https://i-blog.csdnimg.cn/blog_migrate/855f4993623266ec42156f276a912a8e.jpeg)
![fdb558c273ad664e6baa921a729abe28.png](https://i-blog.csdnimg.cn/blog_migrate/7cc2d269818d6de6bd6ad72bab858af5.png)