I have a docker swarm configuration and in there I deployed two stacks (main
and mon
) I can expose a port in one stack and I can refer to it from another. However, I was trying to find a way of not doing that but instead have it access it using the 127.0.0.11 DNS.
In mon
I have a service called grafana
Using https://docs.docker.com/docker-cloud/apps/service-links/#discovering-services-or-containers-on-another-stack which indicated that I can use the stack name to refer to it didn't work when I tried to ping grafana.mon
it just returned invalid host name.
To do this, all you need is to make it use the same network, then they will be visible. In my case I defined a network called
public
, that is referred to externally by all my stacksFrom there in my docker-compose.yml file I have
To access it, just use the service name.
You need to enable both stacks to connect through an overlay network type, and then allow both stacks to use (at least on the service required) the overlay network that was created externally to both stacks.
The overlay network should be created before the stacks go up, so the services that needs to connect through can 'attach' to it.
Create the network like this
Then reference the service name on your env file, you can check what name does your services has calling
Now get the name the service from the NAME column. Ex: bar-stack_tar-service
Notice your services are prefixed by the stack name you give when deploy