Docker Swarm 基础4

2021-11-29 19:17:30 浏览数 (1)

服务发现

Swarm 需要使用到服务发现机制,发现服务是 Swarm 中极其关键的一环,Swarm 依赖它对集群中的其它节点进行感知和交互,集群的高可用也依赖于它完成,如果服务发现工作不正常,集群将无法操作

Swarm 目前支持四种服务发现工具:

  • Hosted (用于测试,不要使用到生产)
  • Consul
  • etcd
  • Zookeeper

下面选择 Consul 作为服务发现工具

代码语言:javascript复制
[root@h104 ~]# docker run -d -p 8500:8500 --name=consul progrium/consul -server -bootstrap
Unable to find image 'progrium/consul:latest' locally
latest: Pulling from progrium/consul
3b4d28ce80e4: Pull complete 
e5ab901dcf2d: Pull complete 
30ad296c0ea0: Pull complete 
3dba40dec256: Pull complete 
f2ef4387b95e: Pull complete 
53bc8dcc4791: Pull complete 
75ed0b50ba1d: Pull complete 
17c3a7ed5521: Pull complete 
8aca9e0ecf68: Pull complete 
4d1828359d36: Pull complete 
46ed7df7f742: Pull complete 
b5e8ce623ef8: Pull complete 
049dca6ef253: Pull complete 
bdb608bc4555: Pull complete 
8b3d489cfb73: Pull complete 
c74500bbce24: Pull complete 
9f3e605442f6: Pull complete 
d9125e9e799b: Verifying Checksum 
Pulling repository docker.io/progrium/consul
e66fb6787628: Download complete 
31f630c65071: Download complete 
cadd1fc80511: Download complete 
617a0e174acf: Download complete 
8142b9305a34: Download complete 
8e614066f6a6: Download complete 
8ba0a056d1e3: Download complete 
d79f17b5cf8f: Download complete 
1222ac49a0eb: Download complete 
8d3315362a90: Download complete 
8359e65c65c1: Download complete 
53d68e7edf50: Download complete 
e57fb0e987c9: Download complete 
39dd286a1371: Download complete 
0ed95048b811: Download complete 
d9333eedb08a: Download complete 
18d2154179cc: Download complete 
ff1cf6216ab6: Download complete 
Status: Downloaded newer image for progrium/consul:latest
docker.io/progrium/consul: this image was pulled from a legacy registry.  Important: This registry version will not be supported in future versions of docker.
3b12ab97b20fc65a74936fb632317358845c5318ac654d768da2c98754a80906
[root@h104 ~]# echo $?
0
[root@h104 ~]# 

多了一个 Consul 的镜像,容器也已经运行起来了

代码语言:javascript复制
[root@h104 ~]# docker images
REPOSITORY                              TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
swarm                                   latest              81127fe5e9b4        2 weeks ago         18.11 MB
docker:5000/ci/jnkns-img                latest              5b825467fc4f        7 weeks ago         708.2 MB
docker:5000/ci/jnkns-img2               latest              efae71df8aca        7 weeks ago         708.2 MB
jenkins                                 latest              5a0e442d31f6        7 weeks ago         708.4 MB
docker:5000/ubuntu                      latest              8693db7e8a00        8 weeks ago         187.9 MB
ubuntu                                  latest              8693db7e8a00        8 weeks ago         187.9 MB
registry                                2                   683f9cd9cf88        11 weeks ago        224.5 MB
daocloud.io/daocloud/daocloud-toolset   latest              1e743a7453e4        11 weeks ago        145.8 MB
hello-world                             latest              0a6ba66e537a        5 months ago        960 B
progrium/consul                         latest              e66fb6787628        8 months ago        69.4 MB
<none>                                  <none>              9f3e605442f6        8 months ago        69.4 MB
[root@h104 ~]#
[root@h104 ~]# docker  ps -a 
CONTAINER ID        IMAGE                       COMMAND                  CREATED             STATUS                     PORTS                                                                            NAMES
3b12ab97b20f        progrium/consul             "/bin/start -server -"   4 minutes ago        Up 4 minutes               53/tcp, 53/udp, 8300-8302/tcp, 8400/tcp, 8301-8302/udp, 0.0.0.0:8500->8500/tcp   consul
236348a3c9ff        docker:5000/ci/jnkns-img2   "/bin/tini -- /usr/lo"   7 weeks ago         Exited (143) 4 weeks ago                                                                                    jenkins01
[root@h104 ~]# 

0 人点赞