使用 docker-compose 批量建立機器

docker-compose 與 Dockerfile

config 目錄:
使用 docker-compose 批量建立機器redis

Dockerfile 文件信息docker

FROM centos:latest
MAINTAINER peter "ttone2@vip.qq.com"
RUN groupadd -r redis && useradd  -r -g redis redis
RUN  yum -y update &&  yum -y install epel-release \
&&   yum -y install redis  && yum -y install wget \
&&   yum -y install net-tools \
&&   yum -y install  ruby && yum  -y install  rubygems
RUN wget https://rubygems.org/downloads/redis-3.2.1.gem  &&  gem install -l ./redis-3.2.1.gem \
&&  rm -f redis-3.2.1.gem
COPY  ./config/redis-trib.rb  /usr/bin
COPY  ./config/redis.sh       /usr/bin
RUN  mkdir -p /config  && chmod  775  /usr/bin/redis.sh && chmod 775 /usr/bin/redis-trib.rb

docker-compose.yamlcentos

version: "3.6"
services:
  redis-master10:
    image: redis-cluster
    container_name: redis-master10
    working_dir: /config
    environment:
      - PORT=6400
    ports:
      - "6400:6400"
      - "16400:16400"
    stdin_open: true
    networks:
      redis-master:
        ipv4_address: 172.50.0.10
    tty: true
    privileged: true
    volumes: ["/home/work/redis-cluster/config:/config"]
    entrypoint:
      - /bin/bash
      - redis.sh
  redis-master11:
    image: redis-cluster
    container_name: redis-master11
    working_dir: /config # 啓動後的工做目錄
    environment:
      - PORT=6401
    ports:
      - "6401:6401"
      - "16401:16401"
    stdin_open: true
    networks:
      redis-master:
        ipv4_address: 172.50.0.11
    tty: true
    privileged: true
    volumes: ["/home/work/redis-cluster/config:/config"]
    entrypoint:
      - /bin/bash
      - redis.sh
  redis-master12:
    image: redis-cluster
    container_name: redis-master12
    working_dir: /config
    environment:
      - PORT=6402
    ports:
      - "6402:6402"
      - "16402:16402"
    stdin_open: true
    networks:
      redis-master:
        ipv4_address: 172.50.0.12
    tty: true
    privileged: true
    volumes: ["/home/work/redis-cluster/config:/config"]
    entrypoint:
      - /bin/bash
      - redis.sh

  redis-slave10:
    image: redis-cluster
    container_name: redis-slave10
    working_dir: /config
    environment:
      - PORT=6402
    networks:
      redis-slave:
        ipv4_address: 172.30.0.10
    ports:
      - "6402:6402"
      - "16402:16402"
    stdin_open: true
    tty: true
    privileged: true
    volumes: ["/home/work/redis-cluster/config:/config"]
    entrypoint:
      - /bin/bash
      - redis.sh

  redis-slave11:
    image: redis-cluster
    container_name: redis-slave11
    working_dir: /config
    environment:
      - PORT=6404
    networks:
      redis-slave:
        ipv4_address: 172.30.0.11
    ports:
      - "6404:6404"
      - "16404:16404"
    stdin_open: true
    tty: true
    privileged: true
    volumes: ["/home/work/redis-cluster/config:/config"]
    entrypoint:
      - /bin/bash
      - redis.sh

  redis-slave12:
    image: redis-cluster
    container_name: redis-slave12
    working_dir: /config
    environment:
      - PORT=6405
    networks:
      redis-slave:
        ipv4_address: 172.30.0.12
    ports:
      - "6405:6405"
      - "16405:16405"
    stdin_open: true
    tty: true
    privileged: true
    volumes: ["/home/work/redis-cluster/config:/config"]
    entrypoint:
      - /bin/bash
      - redis.sh

networks:
  # 主節點的網卡信息
  redis-master:
    driver: bridge
    ipam:
      driver: default
      config:
        -
          subnet: 172.50.0.0/16
    # 從節點的網卡信息
  redis-slave:
    driver: bridge
    ipam:
      driver: default
      config:
        -
          subnet: 172.30.0.0/16
  redis-test:
    external:
      name: mynetwork
相關文章
相關標籤/搜索