创建 network
1
docker network create --driver bridge --subnet 172.22.0.0/16 --gateway 172.22.0.1 op_net
创建 consul.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56version: '3.6'
services:
consul-1:
image: consul
restart: always
hostname: consul-1
container_name: consul-1
command: agent -server -bootstrap-expect=3 -node=consul-1 -bind=0.0.0.0 -client=0.0.0.0 -datacenter=dc1
networks:
default:
ipv4_address: 172.22.0.31
consul-2:
image: consul
restart: always
hostname: consul-2
container_name: consul-2
command: agent -server -retry-join=consul-1 -node=consul-2 -bind=0.0.0.0 -client=0.0.0.0 -datacenter=dc1
depends_on:
- consul-1
networks:
default:
ipv4_address: 172.22.0.32
consul-3:
image: consul
restart: always
hostname: consul-3
container_name: consul-3
command: agent -server -retry-join=consul-1 -node=consul-3 -bind=0.0.0.0 -client=0.0.0.0 -datacenter=dc1
depends_on:
- consul-1
networks:
default:
ipv4_address: 172.22.0.33
consul-4:
image: consul
restart: always
hostname: consul-4
container_name: consul-4
ports:
- 8500:8500
command: agent -retry-join=consul-1 -node=consul-4 -bind=0.0.0.0 -client=0.0.0.0 -datacenter=dc1 -ui
depends_on:
- consul-2
- consul-3
networks:
default:
ipv4_address: 172.22.0.34
networks:
default:
external:
name: op_net启动 Consul 集群
1
docker-compose -f consul.yml up -d
访问 localhost:8500/
基于 Docker 搭建 Consul 集群
小礼物走一走,来 Github 关注我