cabrinoob / rancher-registrator

A registrator-like made for Consul & Rancher
15 stars 16 forks source link

Services without exposed ports not registered #11

Open pasikarkkainen opened 7 years ago

pasikarkkainen commented 7 years ago

In rancher-registrator logs I can see these entries for many services/containers:

5/31/2017 7:24:05 PMNo port mappings for 5/31/2017 7:24:05 PMundefined

And those services/containers don't end up registered in Consul.

docker-compose.yml example:

version: '2' services: lb: image: rancher/lb-service-haproxy:v0.6.4 ports:

And basicly only the "lb" ends up registered in Consul.. it would be nice to be able to get all the other services registered aswell.

pasikarkkainen commented 7 years ago

Oh, and forgot to mention this happens with Rancher version 1.5.10.

pasikarkkainen commented 7 years ago

Reading the source of rancher-registrator.. in function checkForPortMapping() it seems the processing only continues if there are exposed ports in the metadata for the service/container.

So I guess that logic should be modified to deal with services/containers that do not expose ports and only use the rancher internal network for communication inside the stack.

pasikarkkainen commented 7 years ago

It seems Rancher currently doesn't support Docker "expose" functionality for defining container-internal ports, which aren't exposed on the host.. so defining "expose" in docker-compose.yml doesn't help getting the services/containers registered to Consul.

One workaround is to use "ports" without defining the host port, ie. one gets random port from the host mapped to the container internal port. Then rancher-registrator registers the container to Consul just fine.. this isn't a perfect solution, but at least it's some kind of a workaround.

Any plans to add support for registering services/containers without "ports" defined? Another nice feature would be the ability to register to container private/internal IP address aswell..

cabrinoob commented 7 years ago

The aim of rancher-registrator is to register exposed services in consul in order to be reached from outside the stack network. So, only services with an exposed port mapped on the host are registered in consul. For internal communication between services without exposed ports you must use the internal DNS of rancher.

pasikarkkainen commented 7 years ago

It seems current version of Rancher supports "expose" after all in docker-compose.yml, and it seems to work OK.

@cabrinoob : Thanks for the reply. Do you accept new features (PR) to rancher-registrator? I'm thinking of implementing an optional feature (enabled via some label to the service in question) to allow syncing "internal services" to consul aswell.. not only those with published ports.