官方镜像

https://hub.docker.com/r/easymock/easymock

目录结构

➜  docker-compose git:(master) ✗ tree
.
└── easy-mock
    ├── docker-compose.yml
    └── production.json

1 directory, 2 files

docker-compose.yml 内容

version: "3"
services:
  mongodb:
    image: mongo:3.4.1
    volumes:
      # ./data/db 数据库文件存放地址,根据需要修改为本地地址
      - "./data/mongodb:/data/db"
    networks:
      - easy-mock
    restart: always

  redis:
    image: redis:4.0.6
    command: redis-server --appendonly yes
    volumes:
      # ./data/redis redis 数据文件存放地址,根据需要修改为本地地址
      - "./data/redis:/data"
    networks:
      - easy-mock
    restart: always

  web:
    image: easymock/easymock:1.6.0
    command: /bin/bash -c "npm start"
    ports:
      - "7300:7300"
    volumes:
      # 日志地址,根据需要修改为本地地址
      - "./logs:/home/easy-mock/easy-mock/logs"
      # 配置地址,请使用本地配置地址替换
      - "./production.json:/home/easy-mock/easy-mock/config/production.json"
    networks:
      - easy-mock
    restart: always

networks:
  easy-mock:

production.json 内容

注意事项: 配置中连接 mongodb 的主机必须要填写 docker-compose.yml 中的 service 名称,即:mongodb

{
  "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
  }
}

启动

docker-compose up -d

本地访问: http://localhost:7300http://0.0.0.0:7300 即可

参考

https://zhuanlan.zhihu.com/p/91646508