1、拉取镜像
docker pull mongo:3.4 docker pull redis:4.0.6 docker pull easymock/easymock:1.6.0
docker pull nginx
2、建立本地网路
# 创建bridge网络:
docker network create local_net
3、建立文件夹
/app/mongo /app/nginx/webwork
/app/nginx/config/conf.d
/app/nginx/log /app/nginx /app/redis
4、上传easy-mock文件 production.json
{ "port": 7300, "host": "0.0.0.0", "pageSize": 30, "proxy": false, "db": "mongodb://local_mongo:27017/easy-mock", "unsplashClientId": "", "redis": { "keyPrefix": "[Easy Mock]", "port": 6379, "host": "local_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/" } }
5、创建容器
# nginx docker run -tid -p 80:80 \ --name nginx --network local_net --network-alias local_nginx \ -v /app/nginx/webwork:/usr/share/nginx/html \ -v /app/nginx/config/conf.d:/etc/nginx/conf.d \ -v /app/nginx/log:/var/log/nginx \ nginx # mongo docker run -itd -p 27017:27017 \ --name app_mongo --network local_net --network-alias local_mongo \ -v /app/mongo:/data/db \ mongo:3.4 # redis docker run -tid -p 6379:6379 \ --name app_redis --network local_net --network-alias local_redis \ -v /app/redis:/data \ --privileged=true \ redis:4.0.6 redis-server \ --appendonly yes # easy-mock docker run -tid -p 7300:7300 \ --name app_mock --network local_net --network-alias local_mock \ -v /app/easy-mock/logs:/home/easy-mock/easy-mock/logs \ -v /app/easy-mock/production.json:/home/easy-mock/easy-mock/config/production.json \ easymock/easymock:1.6.0 \ /bin/bash -c "npm start"
6、配置nginx,新建配置文件 /app/nginx/config/conf.d/easymock.conf
server { listen 80; server_name xxxx.com; # 监听的域名 location / { proxy_pass http://local_mock:7300; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_set_header X-Forwarded-Proto $scheme; proxy_buffering off; } }
7、进入 nginx 容器,重新家在配置文件
# 然后进入容器,重新加载nginx docker exec -it nginx bash # 修改配置重新加载 nginx -s reload