docker-compose安装consul集群

docker-compose 安装consul集群

  • 创建consul集群专属网络, (默认使用bridge模式)
docker network create my_consul_net
  • 编写docker-compose.yaml文件
    备注:文件中是创建三个server(consul_node1,consul_node2,consul_node3)和一个client(consul_node4),并在consul_node4上面提供 web UI 服务,web访问端口是8500
version: '3'
networks:
  my_consul_net:

services:
  consul1:
    image: consul
    container_name: consul_node1
    command: agent -server -bootstrap-expect=3 -node=consul_node1 -bind=0.0.0.0 -client=0.0.0.0 -datacenter=dc1
    networks:
      - my_consul_net

  consul2:
    image: consul
    container_name: consul_node2
    command: agent -server -retry-join=consul_node1 -node=consul_node2 -bind=0.0.0.0 -client=0.0.0.0 -datacenter=dc1
    depends_on:
      - consul1
    networks:
      - my_consul_net

  consul3:
    image: consul
    container_name: consul_node3
    command: agent -server -retry-join=consul_node1 -node=consul_node3 -bind=0.0.0.0 -client=0.0.0.0 -datacenter=dc1
    depends_on:
      - consul1
    networks:
      - my_consul_net

  consul4:
    image: consul
    container_name: consul_node4
    command: agent -retry-join=consul_node1 -node=consul_node4 -bind=0.0.0.0 -client=0.0.0.0 -datacenter=dc1 -ui
    ports:
    - 8500:8500
    depends_on:
      - consul2
      - consul3
    networks:
      - my_consul_net
  • 使用命令启动
docker-compose up -d
  • 查看consul集群容器
docker ps
#
docker ps
CONTAINER ID   IMAGE                 COMMAND                  CREATED         STATUS          PORTS                                                                                                         NAMES
978a8dc3951d   consul                "docker-entrypoint.s…"   7 seconds ago   Up 7 seconds    8300-8302/tcp, 8301-8302/udp, 8600/tcp, 8600/udp, 0.0.0.0:8500->8500/tcp                                      consul_node4
60751f7d89ff   consul                "docker-entrypoint.s…"   8 seconds ago   Up 7 seconds    8300-8302/tcp, 8500/tcp, 8301-8302/udp, 8600/tcp, 8600/udp                                                    consul_node2
c1bfec5fb452   consul                "docker-entrypoint.s…"   8 seconds ago   Up 7 seconds    8300-8302/tcp, 8500/tcp, 8301-8302/udp, 8600/tcp, 8600/udp                                                    consul_node3
b582291c3726   consul                "docker-entrypoint.s…"   8 seconds ago   Up 8 seconds    8300-8302/tcp, 8500/tcp, 8301-8302/udp, 8600/tcp, 8600/udp                                                    consul_node1
  • 浏览器端访问127.0.0.1:8500
    image.png

你可能感兴趣的:(docker-compose安装consul集群)