3

I've got a consul agent running on my host machine, and a couple of services running inside docker containers. I'm using 'gliderlabs/registrator' to discover these services and register them with the local consul agent.

The consul agent is configured to accept connections from everywhere ("client_addr": "0.0.0.0" option), which I can "prove" by doing dig @172.17.42.1 -p 8600 someservice.service.consul from the host machine.

Problem is that I don't seem to be able to do the same from within the containers, the dig request just times out and I can't curl it either. I do pass --dns 172.17.42.1. Any ideas?

Note: I want to avoid using --net=host if possible.

Thanks!

3

I was hitting the same roadblock, and your setup and mine look really similar (I'm running Consul standalone rather than as a Docker container).

I am also against using --net=host !!!.

What made it work in my case was:

a) I've created a config.json for Consul, and inside of it I've set up the ports.dsn property to use port 53 (DNS default).

You can't use 8600 inside of Docker containers, this is because the docker run --dns argument does not allow you to give a port.

b) I've used the LAN (private) IP of the host as the --dns value. I've tried with other values before (0.0.0.0, public IP and 127.0.0.1) but those weren't working.

c) Optional: You can add --dns-search="service.consul" to the docker run so you can have shorter domain names (i.e avoid having to write the service.consul part).

Once inside of the container, you can execute a nslookup ubuntu.service.consul provided that's the service name you have for that container.

Important notes:

  • You need to expose ports (i.e -P or -p flag) on the container for registrator to pick them up. If you don't share a port, registrator will silently ignore the container.
  • It is nice to setup a hostname (using -h flag).

Hope this helps!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.