docker-compose部署常用服务

 

建议看此篇文章前先看以下4篇博文:Docker中以redis.conf配置文件启动Redis

一、docker-compose编写

docker-compose.yml其实就是docker命令脚本,可以在docker-compose.yml中配置多条docker命令,实现同时启动多个服务的目的。在任意目录中创建docker-compose.yml,比如我的与redis配置文件放在同一目录下:

docker-compose部署常用服务_第1张图片

在 docker-compose.yml 文件中写入下列内容:

version: '3'
services:
  # 1.部署redis服务
  redis-master:
    image: redis
    container_name: redis-master
    ports:
      - 6379:6379
    volumes:
      - ./redis/redis.conf:/usr/local/etc/redis/redis.conf
      - ./redis/redis-master/data:/data
    command:
      redis-server /usr/local/etc/redis/redis.conf --appendonly yes
  
  # 2.部署rabbitmq服务
  rabbitmq:
    image: rabbitmq:management
    container_name: rabbitmq
    restart: always
    hostname: myRabbitmq
    ports:
      - 15672:15672
      - 5672:5672
    volumes:
      - ./rabbitmq/data:/var/lib/rabbitmq
    environment:
      - RABBITMQ_DEFAULT_USER=root
      - RABBITMQ_DEFAULT_PASS=123456
  # 3.部署jmeter服务
  jmeter-slave-01:
    image: runcare/jmeter-slave
    container_name: jmeter-slave-01
    ports:
      - 1101:1101
    volumes:
      - ./jmeter/slave-01/web:/usr/local/etc/jmeter/slave-01/web
      - ./jmeter/slave-01/jmx:/usr/local/etc/jmeter/slave-01/jmx
      - ./jmeter/slave-01/jtl:/usr/local/etc/jmeter/slave-01/jtl

  jmeter-slave-02:
    image: runcare/jmeter-slave
    container_name: jmeter-slave-02
    ports:
      - 1102:1102
    volumes:
      - ./jmeter/slave-02/web:/usr/local/etc/jmeter/slave-02/web
      - ./jmeter/slave-02/jmx:/usr/local/etc/jmeter/slave-02/jmx
      - ./jmeter/slave-02/jtl:/usr/local/etc/jmeter/slave-02/jtl

  jmeter-slave-03:
    image: runcare/jmeter-slave
    container_name: jmeter-slave-03
    ports:
      - 1103:1103
    volumes:
      - ./jmeter/slave-03/web:/usr/local/etc/jmeter/slave-03/web
      - ./jmeter/slave-03/jmx:/usr/local/etc/jmeter/slave-03/jmx
      - ./jmeter/slave-03/jtl:/usr/local/etc/jmeter/slave-03/jtl

二、启动docker-compose

在 docker-compose.yml 所在目录下执行 docker-compose up -d,即可在 Docker 中生成 docker-compose.yml所配置的容器,在docker-Dash board中查看容器

docker-compose部署常用服务_第2张图片

三、测试连接

1、redis连接测试

 

docker-compose部署常用服务_第3张图片

2、rabbitmq连接测试

docker-compose部署常用服务_第4张图片

你可能感兴趣的:(云原生)