gpt4 book ai didi

spring-boot - Spring Cloud Consul和Consul客户端 docker 化

转载 作者:行者123 更新时间:2023-12-02 21:02:17 25 4
gpt4 key购买 nike

我有2个应用程序,都使用Spring Boot编写。两者都在不同的Docker容器中运行。我也有领事在另一个Docker容器中运行。我已经使用docker-compose.yml文件将端口8500公开给领事。因此,如何为我的Spring Boot应用程序指定在哪里注册自己,即领事在哪里运行。是否提供映射端口的地址(映射到本地计算机的端口)或其他更改?

我现在使用的示例:https://github.com/Java-Techie-jt/cloud-consul-service-discovery

编辑:

docker-compose.yml:

version: "2"

services:
consul:
container_name: consul
image: consul
expose:
- "8300"
- "8400"
- "8500"
restart: always
registrator:
container_name: registrator
image: gliderlabs/registrator:master
volumes:
- "/var/run/docker.sock:/tmp/docker.sock"
command: -internal consul://consul:8500
restart: always
depends_on:
- consul
web1:
image: deis/mock-http-server
container_name: web1
expose:
- "8080"
environment:
SERVICE_NAME: "web"
SERVICE_TAGS: "web"
restart: always
depends_on:
- registrator
web2:
image: deis/mock-http-server
container_name: web2
expose:
- "8080"
environment:
SERVICE_8080_NAME: "web"
SERVICE_8080_TAGS: "web"
restart: always
depends_on:
- registrator
haproxy:
build: ./haproxy
container_name: my-haproxy
image: anthcourtney/haproxy-consul
ports:
- 80
depends_on:
- web1
- web2
test:
container_name: test-client
build: ./test
depends_on:
- haproxy

networks:
default:

最佳答案

您可以将注册器用于服务注册。
Registrator通过检查容器在线来自动为任何Docker容器注册和注销服务。 Registrator支持可插拔服务注册表,当前包括Consul,etcd和SkyDNS 2。

您可以将注册器作为容器运行,它将注册应用程序的每个端口。以下是示例撰写文件:-

  version: '2'
services:
registrator:
image: "${REGISTRY}gliderlabs/registrator:latest"
command: [
"-ip=<docker-host-ip>",
"-retry-attempts", "100",
"-cleanup",
# "-internal",
"consul://vconsul:8500"
]

官方文档: https://gliderlabs.github.io/registrator/latest/

关于spring-boot - Spring Cloud Consul和Consul客户端 docker 化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60034547/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com