我是一个码头工人。我有两个python Flask应用程序正在迁移以作为docker服务运行,其中一个需要调用另一个。 我使用nginx反向代理来管理与服务的外部连接。在
nginx位置设置为:
location /alpha/ {
proxy_pass https://alpha-app:5000/;
}
location /beta/ {
proxy_pass https://beta-app:5001/;
}
在docker swarm中运行时,其中“demo”是堆栈名称:
^{pr2}$我可以从外部访问服务:
https://my-host/alpha/some_endpoint
https://my-host/beta/some_endpoint
现在我需要alpha呼叫beta版的服务。 如果我在普通docker容器中运行这些应用程序,那么以下从alpha到beta的调用是有效的:
url = https://my-host/beta/some_endpoint
requests.get(url, cert, verify)
请注意,在docker swarm中运行时,应用程序运行在不同的主机上,但使用同一网络。 当应用程序作为docker群中的服务运行时,我无法使应用程序到应用程序的连接正常工作。 我仍然可以从群外给每个应用程序服务打电话:
https://my-host/alpha/some_endpoint -> works
https://my-host/beta/some_endpoint -> works
我不能让alpha使用beta版的服务。 我试过只使用服务名称:
url = https://beta-app/some_endpoint -> connection refused
url = https://beta-app:5001/some_endpoint -> hostname doesn't match
url = https://my-host/beta/some_endpoint > name or service not known
在请求.get()总是失败
一个docker swarm服务调用另一个docker swarm服务的正确url是什么? 我需要查找服务的内部IP吗?在
使用
Service name
作为host
将有助于在同一覆盖网络上运行在docker swarm中的两个docker服务/容器之间进行通信。在参考号:https://docs.docker.com/v17.12/docker-cloud/apps/service-links/#discovering-containers-on-the-same-service-or-stack
堆栈文件示例: 测试.yml在
部署:
sudo docker stack deploy -c test.yml test
API调用:
curl http://localhost:5000
。 此呼叫将转到主服务,主服务将呼叫碎片服务。在主人(应用程序副本)公司名称:
^{pr2}$碎片(应用程序副本)公司名称:
主机和碎片的Dockerfile:
相关问题 更多 >
编程相关推荐