Service Discovery in docker container

Ok, I’m using, and am new to both Nomad and Consul, and I’m trying to wrap my head around how to set this up smoothly.

Specifically, I’m trying to figure out how to do service discovery inside of a docker container. So, all of my nodes are running consul agent, so if I run a standard exec job, it’s pretty easy to use dig @ -p 8600 or some other local dns tools to figure that out.

But, say now I use nomad to launch a docker task, that gets put on a virtual network, and it seems no-longer easy to find the correct address to connect to the agent on the host.

Alternatively, I can of course copy consul agent itself into all of my images, but it seems that I still have the problem of giving consul an ip address to connect to.

How are others solving this sort of problem? Is there just something big that I entirely missed?


Did you already study these?

Yeah, I’ve taken a look at both of those.

the service stanza is mostly about publish services as far as I can tell, which is useful, but doesn’t seem to apply for service discovery.

The consul integration document seems to have a link to the template specification which looks like it might be useful for service discovery, but it seems like it would be difficult to use that for discovery of long-lived services without restarting the service or having a more complicated signaling setup, whereas dns support would just work.

I feel like using consul dns in a docker container has to be a common usage scenario, right?