I am a docker swarm noob. I have two python Flask apps that are being migrated to run as docker services, and one needs to call the other. I am using nginx reverse proxy to manage external connections to the services.
The nginx locations settings are:
location /alpha/ {
proxy_pass https://alpha-app:5000/;
}
location /beta/ {
proxy_pass https://beta-app:5001/;
}
When running in docker swarm, where "demo" is the stack name:
$ sudo docker service ls:
NAME PORTS
demo_alpha *:3002->5000/tcp
demo_beta *:3001->5001/tcp
demo_nginx *:443->443/tcp
I can access the services externally at:
https://my-host/alpha/some_endpoint
https://my-host/beta/some_endpoint
Now I need to have alpha call a service in beta. If I run the apps in regular docker containers, then the following call from alpha to beta works:
url = https://my-host/beta/some_endpoint
requests.get(url, cert, verify)
Note that when running in docker swarm, the apps are running on different hosts, but using the same network. I can't get the app to app connection to work when the apps are running as services in a docker swarm. I can still call each app service from outside of the swarm:
https://my-host/alpha/some_endpoint -> works
https://my-host/beta/some_endpoint -> works
I cannot get alpha to consume a service from beta. I have tried just using the service name:
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
requests.get() always fails
What is the correct url to use for one docker swarm service to call another? Do I need to look up the service's internal IP?