Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/docker/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Api 使用zuul在docker中路由到不同的容器不工作_Api_Docker_Netflix Zuul_Api Gateway - Fatal编程技术网

Api 使用zuul在docker中路由到不同的容器不工作

Api 使用zuul在docker中路由到不同的容器不工作,api,docker,netflix-zuul,api-gateway,Api,Docker,Netflix Zuul,Api Gateway,我有两个微服务(spring boot应用程序)运行在不同的docker容器中,并配置了zuul api网关。路由到其他容器不起作用。容器1在8030端口上运行,容器2在8030端口上运行 下面是application.yml中的zuul配置- server: port: 8030 # TODO: figure out why I need this here and in bootstrap.yml spring: application: name: zuul serve

我有两个微服务(spring boot应用程序)运行在不同的docker容器中,并配置了zuul api网关。路由到其他容器不起作用。容器1在8030端口上运行,容器2在8030端口上运行

下面是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
当通过localhost:8030/zuultest/test进行访问时,我得到的异常为-

2016-09-19 09:10:14.597  INFO 1 --- [nio-8030-exec-3] hello.SimpleFilter                       : GET request to http://localhost:8030/zuultest/test
2016-09-19 09:10:14.600  WARN 1 --- [nio-8030-exec-3] o.s.c.n.z.filters.post.SendErrorFilter   : Error during filtering

我能知道为什么我会收到这个吗?

你是如何启动这两个容器的?如果将它们暴露给docker主机,则两者不能具有相同的端口

docker run --name service A --net=host -p 8030:8030 ...
docker run --name service B --net=host -p 8030:8031 ...
否则,如果调用localhost:8030,则调用的是主机(而不是容器),并且不会得到响应


当您使用不同的端口启动它们时,需要将端口映射到主机,并使用localhost将它们调用到右侧公开的端口

您是如何启动这两个容器的?如果将它们暴露给docker主机,则两者不能具有相同的端口

docker run --name service A --net=host -p 8030:8030 ...
docker run --name service B --net=host -p 8030:8031 ...
否则,如果调用localhost:8030,则调用的是主机(而不是容器),并且不会得到响应


当您使用不同的端口启动它们时,需要将端口映射到主机,并使用localhost将它们调用到右侧公开的端口

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

demo1:
  image: <demo1 image name>
  links: - demo2
demo2:
  image: <demo2 image name>
demo1:
图片:
链接:-演示2
演示2:
图片:

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

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

demo1:
  image: <demo1 image name>
  links: - demo2
demo2:
  image: <demo2 image name>
demo1:
图片:
链接:-演示2
演示2:
图片:
然后在zuul:routs:url配置中,您可以使用conatiner名称demo2而不是它的IP