registrator icon indicating copy to clipboard operation
registrator copied to clipboard

Registrator will not create consul services for the docker 1.12 service containers.

Open cohenaj194 opened this issue 8 years ago • 16 comments

This mainly an issue related to the newest version of docker (docker 1.12) and the new version of docker swarm. It has most likely occurred because this project is not up to date with the experimental version of docker. The newest version of docker has a built in version of swarm that deploys containers as docker services. These containers are not directly connected to ports on the swarm worker nodes and as such are not discovered by registrator. Instead they require a docker network, which automatically load balances any containers of a service on a server through a single pre-defined port. So all the containers are essentially attached to the same port, but indirectly so. Right now registrator is not discovering either the containers or the load balanced port.

Here is an example for recreating a docker service that fails to be registered by registrator:

docker network create -d overlay mynet
docker service create –name frontend –replicas 5 -p 80:80/tcp –network mynet nginx

cohenaj194 avatar Jul 07 '16 17:07 cohenaj194

Currently, creation of services isn't exposed through events, so I don't think there's anything that can be done until docker provides such events. It looks like it's already on the roadmap, though: docker/docker#23827

jeinwag avatar Jul 11 '16 09:07 jeinwag

What about rudimentary polling of: https://docs.docker.com/engine/reference/api/docker_remote_api_v1.24/#/3-8-services

bitsofinfo avatar Jul 22 '16 13:07 bitsofinfo

With Docker 1.13, services have the ability to publish ports in host mode (the same as with standalone containers).

jeinwag avatar Jan 09 '17 09:01 jeinwag

We are labeling containers (instead of services), with docker service create --container-label SERVICE_80_NAME=wp-nginx-{{podId}}{{container_suffix}} ... this way our registrator can see it ;)

On 1 February 2017 at 16:14, marcuslinke [email protected] wrote:

Probably I've overseen something but wouldn't it be possible to support docker swarm labels at least? When a service is created this means some containers are created / started and the appropriate docker events are fired. If registrator could use swarm labels for service naming should'nt it suffice?

docker inspect redis.1.8uj3q8o43vfe7b4nct99d4g3u ... "Labels": { "com.docker.swarm.node.id": "vpq694ms5z19r4ucn7qupj7xy", "com.docker.swarm.service.id": "s1gbqnsivxi1yz0ihvan7epc1", "com.docker.swarm.service.name": "redis", "com.docker.swarm.task": "", "com.docker.swarm.task.id": "8uj3q8o43vfe7b4nct99d4g3u", "com.docker.swarm.task.name": "redis.1.8uj3q8o43vfe7b4nct99d4g3u" } ...

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/gliderlabs/registrator/issues/443#issuecomment-276683208, or mute the thread https://github.com/notifications/unsubscribe-auth/AAX_M96c_cX3Z-afk2qEc5Txjj8UZhYGks5rYKFZgaJpZM4JHTTj .

sitamet avatar Feb 02 '17 15:02 sitamet

@sitamet Solved my problem, thank you :-)

logankoester avatar Mar 04 '17 21:03 logankoester

Hi, I have registered service but heath check is failing, could you give me some directions ?

I would like to register service to consul and be able to handle request to this service from fabio.

Thanks in advance.

pipozzz avatar Mar 22 '17 11:03 pipozzz

anyone find a method to do this with @sitamet method

docker service create --container-label SERVICE_6379_NAME=wp-redis -p 6379:6379 --network stackdemo_my-net redis

i get this in registrator :

2017/05/04 11:32:55 ignored: afb4eab7e999 port 6379 not published on host

sulphur avatar May 04 '17 11:05 sulphur

@sulphur If you don't expose your ports to the host, run registrator with the option to register "the exposed" ports:

-internal		Use exposed ports instead of published ports

sitamet avatar May 04 '17 16:05 sitamet

normally i expose them(unless i do it wrong :) ) i will try the internal that should fix my problem for non-exposed containers :) thanks

sulphur avatar May 05 '17 12:05 sulphur

dont work for me :(

docker service create --name tomcat_PROD --container-label SERVICE_8030_NAME=tomcat_PROD -p 8030:8030/tcp --mount type=bind,source=/mnt/tomcat_PROD/conf,target=/opt/tomcat/conf --mount type=bind,source=/mnt/tomcat_PROD/redouteapps,target=/opt/tomcat/redouteapps --mount type=bind,source=/mnt/tomcat_PROD/logs,target=/opt/tomcat/logs --replicas=4 docker01:5000/centos_java8_tomcat8.5.16

gabrielfsousa avatar Aug 11 '17 16:08 gabrielfsousa

with option -internal works, whats the downsize of using -internal ?

gabrielfsousa avatar Aug 11 '17 17:08 gabrielfsousa

It looks like swarm events are now available as of Docker 17.06: https://github.com/moby/moby/issues/23827

Having registrator pick up docker services would be extremely useful !

marzlarz avatar Dec 05 '17 13:12 marzlarz

is registrator picking up docker services now?

I faced the same issue as mentioned in this chain. When running as a docker container (using docker run), port information is added properly into Consul registry. But, when running as a service (using docker service create), I can see from the registrator logs that the service is ignored as the port is not published. I tried adding the --container-label option which did not help me. Adding -internal option when starting the registrator worked, but it is registering exposed ports and not the published ports (this is my requirement).

sumanthjoel avatar Jul 06 '18 07:07 sumanthjoel

any update?

xiaods avatar Sep 16 '18 13:09 xiaods

Registrator seems to work if you use Docker compose file version 3.2 with the "long syntax" for ports. Addition of mode: host seems to make the difference because it causes docker ps on the node running the container to show port information. Also works with ephemeral ports. For example:

version: '3.2'
services:
  web1:
    image: solsson/http-echo:latest
    ports:
      - target: 80
        published: 8081
        mode: host
    environment:
      PORT: 80
      SERVICE_80_NAME: "web1-api"
      SERVICE_NAME: "web1-api"
      SERVICE_TAGS: "web1-tag1"

ionosphere80 avatar Sep 19 '18 21:09 ionosphere80

@ionosphere80 Thanks! your solution works for me. But I am not able to understand why??

Does anyone know what is the default value of "mode" when we set it up normally like below.

ports:
  - '8080:80'

Why does docker stack deploy command not cause docker ps on the node running the container to show port information?

rash805115 avatar Dec 23 '20 16:12 rash805115