[wolf@wulaoer.org 🔥🔥🔥🔥 ~ ]$ docker service ls ID NAME MODE REPLICAS IMAGE PORTS n3e405asfpgi category replicated 1/1 registry-vpc.cn-beijing.aliyuncs.com/rdgtestlinshi/category-prod:19 b5fgjmqbdz8b clound-ui replicated 1/1 registry-vpc.cn-beijing.aliyuncs.com/rdgtestlinshi/clound-ui:1.1.8 *:80->80/tcp, *:443->443/tcp, *:6458->6458/tcp kjj2usz3uh7i config replicated 1/1 registry-vpc.cn-beijing.aliyuncs.com/rdgtestlinshi/config-prod:19 *:8888->8888/tcp bzbjez4fke2r css replicated 1/1 registry-vpc.cn-beijing.aliyuncs.com/rdgtestlinshi/css-prod:27 q17fisiki0z4 eureka replicated 1/1 registry-vpc.cn-beijing.aliyuncs.com/rdgtestlinshi/eureka-prod:19 *:9001->9001/tcp czz4rors2jkr gateway replicated 1/1 registry-vpc.cn-beijing.aliyuncs.com/rdgtestlinshi/gateway-prod:19 7hwx58tqerku hrs replicated 1/1 registry-vpc.cn-beijing.aliyuncs.com/rdgtestlinshi/hrs-prod:19 jftkv24nz7wr oauth replicated 1/1 registry-vpc.cn-beijing.aliyuncs.com/rdgtestlinshi/oauth-prod:19 cdfrqjo5amx2 prm replicated 1/1 registry-vpc.cn-beijing.aliyuncs.com/rdgtestlinshi/prm-prod:19 nm7l3euf64fw xn replicated 1/1 registry-vpc.cn-beijing.aliyuncs.com/rdgtestlinshi/xn-prod:21 4ec5eigtr70o category replicated 2/2 registry-vpc.cn-beijing.aliyuncs.com/rdgtestlinshi/category-prod:19 59y8k21mj085 gateway replicated 0/2 registry-vpc.cn-beijing.aliyuncs.com/rdgtestlinshi/gatewat-prod:v1.0.1 *:9999->9999/tcp
在这里有一个category服务是通过stack创建的,所以我们只做两个测试,一个是在category这个服务中请求service创建的服务,另外在service创建的服务中请求category创建的服务,两边都可以请求,我们认定这个swarm环境通过service和stack创建的服务通信没有问题。下面先使用service创建的服务中请求category,访问code201,说明访问成功。
[wolf@wulaoer.org 🔥🔥🔥🔥 ~ ]$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES b52e36a57d72 registry-vpc.cn-beijing.aliyuncs.com/rdgtestlinshi/category-prod:19 "/bin/bash enpoint" 16 hours ago Up 16 hours category.1.max28p5qhyoiuptnuhwftkj42 11eb3a35c4c8 registry-vpc.cn-beijing.aliyuncs.com/rdgtestlinshi/eureka-prod:19 "/bin/bash enpoint" 17 hours ago Up 17 hours eureka.1.ka58bnsyroqlyjcl25zbbpdd4 005d94a722bc registry-vpc.cn-beijing.aliyuncs.com/rdgtestlinshi/category-prod:19 "/bin/bash enpoint" 2 days ago Up 2 days category.1.gevxchbwgscocmutmz3u5h4tc dd5ddb3e0c2f registry-vpc.cn-beijing.aliyuncs.com/rdgtestlinshi/gateway-prod:19 "/bin/bash enpoint" 2 days ago Up 2 days gateway.1.bckk55i0bxxtfhgip6e5avvui b4a3b509827f registry-vpc.cn-beijing.aliyuncs.com/rdgtestlinshi/oauth-prod:19 "/bin/bash enpoint" 2 days ago Up 2 days oauth.1.ao50j28x7vdp24yr2w37fl98w cbf9d8fba486 registry-vpc.cn-beijing.aliyuncs.com/rdgtestlinshi/css-prod:27 "/bin/bash enpoint" 2 days ago Up 2 days css.1.0f4ng1jlz3b333xu0c3vffm37
这里是在css服务中请求category服务
[wolf@wulaoer.org 🔥🔥🔥🔥 ~ ]$ docker exec -it cbf9d8fba486 /bin/bash [root@cbf9d8fba486 /]# curl category:8087 {"code":201,"msg":"Full authentication is required to access this resource","data":"Full authentication is required to access this resource"}[root@cbf9d8fba486 /]# exit
这里使用category创建的服务请求service创建的服务。在category中请求css
[wolf@wulaoer.org 🔥🔥🔥🔥 ~ ]$ docker exec -it b52e36a57d72 /bin/bash [root@b52e36a57d72 /]# curl css:8083 {"code":201,"msg":"Full authentication is required to access this resource","data":"Full authentication is required to access this resource"}[root@b52e36a57d72 /]#
需要注意的是两个服务都没有做端口映射,所以在swarm中,是有自己的dns解析的,而且不需要映射到宿主机,可以直接请求 这是在swarm集群中有自己的dns和网络以及负载均衡,不需要自己额外的部署。
您可以选择一种方式赞助本站
支付宝扫一扫赞助
微信钱包扫描赞助
赏