【问题标题】:routing to other containers using zuul in docker在 docker 中使用 zuul 路由到其他容器
【发布时间】:2017-01-26 18:51:29
【问题描述】:

我正在使用 docker 在两个容器中运行两个微服务,例如 demo1 和 demo2。我在demo1中配置了zuul。我想从demo1路由​​到demo2,也就是我想从demo1访问demo2中的api。

demo1 在端口 8080 上运行,demo2 在端口 8030 上运行,我想像这样访问 api-“localhost:8030/zuultest/test”。但是路由不起作用。如果我像“localhost:8080/test”一样访问demo1,它工作正常。

这是我在application.yml中的zuul配置-

server:
  port: 8030

#TODO: figure out why I need this here and in bootstrap.yml
spring:
  application:
    name: zuul server

endpoints:
  restart:
    enabled: true
  shutdown:
    enabled: true
  health:
    sensitive: false

zuul:
  routes:
    zuultest:
         url: http://localhost:8080
         stripPrefix: false 

ribbon:
  eureka:
    enabled: false

【问题讨论】:

    标签: docker netflix-zuul


    【解决方案1】:

    您可以使用 docker-compose.yml 中的 links 选项来链接两个容器。

    demo1:
      image: <demo1 image name>
      links:
       - demo2
    demo2:
      image: <demo2 image name>
    

    然后在 zuul:routs:url 配置中,您可以使用容器名称 demo2 而不是它的 IP。

    【讨论】:

      【解决方案2】:

      您还需要确保相关端口是开放的并且可以从外部机器访问。 更好的是,您可以将流量从端口 8080(默认开放端口)路由到所需的端口,在您的情况下为 8030。 显式暴露端口,请参考链接: https://github.com/wsargent/docker-cheat-sheet#exposing-ports

      【讨论】:

        猜你喜欢
        • 2017-01-26
        • 1970-01-01
        • 2018-09-21
        • 1970-01-01
        • 2020-04-29
        • 1970-01-01
        • 2023-03-03
        • 2023-04-06
        • 2022-10-14
        相关资源
        最近更新 更多