【发布时间】:2021-03-21 02:19:15
【问题描述】:
我使用 docker 来构建 UI 和一些后端微服务,并使用 Spring Zuul 作为代理将 Restful API 调用从 UI 传递到下游微服务。我的UI项目需要在构建前在JS文件中指定IP地址,Zuul项目也需要为下游微服务指定IP地址。这样在启动容器后,我可以使用我的 docker 机器 IP http://192.168.10.1/myapp 访问我的应用程序,浏览器网络选项卡中的 restful API 调用将是 http://192.168.10.1/mymicroservices/getProduct 等。
我可以将所有 IP 设置为我的 docker 机器 IP 并毫无问题地构建它们。但是对于我在其他国家的同事,他们的 docker 机器 IP 会有所不同。如何让docker使用特定的IP,例如192.168.10.50,我可以在UI项目和Zuul Proxy项目中设置,这样每个人的docker IP都是一样的,不管他们实际的docker机器IP是多少是吗?
我尝试过的:
- 我在 VirtualBox 中尝试过端口转发。它适用于 UI,但 RESTful API 调用失败。
- 我也尝试了这篇文章中提到的解决方案: Assign static IP to Docker container 但是我无法使用容器 IP 地址从浏览器访问服务。
你有更好的想法吗?谢谢!
【问题讨论】:
-
My UI project needs to specify an IP address in the JS file before the build, and the Zuul project also needs to specify the IP addresses for the downstream microservices.- 这听起来很奇怪。你不能使用主机名而不是硬编码的 IP 吗? -
嗨,Shashank,您的意思是使用 localhost 还是 127.0.0.1?当我在 docker 中构建图像并运行容器时,这不起作用。
标签: docker virtualbox docker-machine docker-networking docker-network