Not all services are registered in Consul with Registrator

I have Docker and Docker Compose on my machine and I have a docker-compose.yml file. Inside of this file I define two services like so

 ...
 nginx:
     build:
         context: ./nginx-proxy' 
     image: nginx-proxy
     container_name: nginx
     ports:
         - 8181:80
     links:
         - consul-server
         - php
     depends_on:
         -registrator

php:
    build:
        context: ./php-apache
    image: php-apache
    container_name: php-apache
    depends_on:
        - registrator

...

It is quite a big docker-compose.yml file, which also contains definitions of consul-server and registrator containers. At first glance, everything works good. When I run:

  • docker change Ctrl+p to something else?
  • Node.js docker container runs when folder is located on desktop but wont in C drive
  • Docker Engine command run --blkio-weight doesn't work
  • Can't build openjdk:8-jdk image directly
  • NuoDB setup on Docker for MacOS. Connection to NuoDB failed. [08S01] Could not connect to any host
  • Can you please suggest on best ways to cleanup docker containers
  • $ docker-compose up
    

    I see that all my containers are running and I see no error messages. I can even check, that for example php container is indeed running (just going to localhost:8181, I see a nice html page rendered with this service). However, the problem is, this php service is not registered with Registrator. I check it like so:

    $ curl 127.0.0.1:8500/v1/catalog/services
    

    As a result, I get this:

    {"consul-server-8500":[], "nginx-proxy-80":[]}
    

    So, for some strange reason Registrator registered successfully nginx-proxy service, but skipped php service. I wonder why. I really need it, since based on this, I would create consul templates for nginx-proxy service. So, I need some help.

    EDIT

    This is how I define consul and registrator services:

    version: '2'
    services:
        consul-server:
            build:
                context: ./consul-server
            hostname: ${MYHOST}
            ports:
                - 8500:8500
        registrator:
            build:
                context: ./registrator
            container_name: registrator
            command: "consul://${MYHOST}:8500"
            hostname: ${MYHOST}
            network_mode: host
            depends_on:
                - consul-server
            volumes:
                - /var/run/docker.sock:/tmp/docker.sock
    

    And this is how my registrator Dockerfile looks like:

    FROM gliderlabs/registrator:latest
    ENV SERVICE_ID=registrator
    ENV SERVICE_NAME=registrator
    ENTRYPOINT ["/bin/registrator"]
    

    Registrator log

    Not sure, if it is important:

    2017/01/17 11:52:52 Starting registrator v7 ...
    2017/01/17 11:52:52 Using consul adapter: consul://127.0.0.1:8500
    2017/01/17 11:52:52 Connecting to backend (0/0)
    2017/01/17 11:52:52 consul: current leader
    2017/01/17 11:52:52 Listening for Docker events ...
    2017/01/17 11:52:52 Syncing services on 2 containers
    2017/01/17 11:52:52 ignored: c7251ebcbec4 no published ports
    2017/01/17 11:52:52 ignored: d22263dca979 port 8301 not published on host
    2017/01/17 11:52:52 ignored: d22263dca979 port 8302 not published on host
    2017/01/17 11:52:52 ignored: d22263dca979 port 8600 not published on host
    2017/01/17 11:52:52 ignored: d22263dca979 port 8600 not published on host
    2017/01/17 11:52:52 ignored: d22263dca979 port 8300 not published on host
    2017/01/17 11:52:52 ignored: d22263dca979 port 8302 not published on host
    2017/01/17 11:52:52 ignored: d22263dca979 port 8301 not published on host
    2017/01/17 11:52:52 added: d22263dca979 consul
    2017/01/17 11:52:52 ignored: d22263dca979 port 8400 not published on host
    2017/01/17 11:52:52 ignored: c7251ebcbec4 no published ports
    2017/01/17 11:52:52 ignored: 74a190734619 port 80 not published on host
    2017/01/17 11:52:53 added: bd9f65b332a5 nginx
    2017/01/17 11:52:53 ignored: bd9f65b332a5 port 443 not published on host
    

    As far as I can see Registrator ignores my php service (docker id=74a190734619). But I do not know how can I fix it.

  • MPI in docker container over docker network hangs
  • Docker Network inside a container partially working
  • Symfony app deployment with docker
  • Connect to a Service running inside a docker container from outside
  • Unable to access Container url in Bluemix for Spring Boot Application
  • Packer instance accessing private Docker registry in AWS
  • One Solution collect form web for “Not all services are registered in Consul with Registrator”

    According to logs registrator registers only those ports which published to your host. And it make sense. Consul is service discovery tool and there is no sense to register services which has no published ports.

    P.S. you can remove links from your docker-compose as you are using version 2 (links are deprecated and networks usage more preferable). It’s not about your problem. Just advice.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.