Unable to register Docker service with Registrator

I have a docker, docker-compose and Consul installed on my local machine. Now I want to register one of my services in Consul using Registrator. The Dockerfile of my service is as simple as:

FROM php:7.0-apache
COPY code/ /var/www/html/
ENV SERVICE_ID=php
ENV SERVICE_NAME=php-apache

Besides, I have Consul running. I can check it with simple commands like:

  • Multiservice application in Teamcity - composing branches
  • Spring boot app fail to link consul in docker
  • Unable to access Container url in Bluemix for Spring Boot Application
  • Is it reasonable to containerize development environment with Docker?
  • Kubernetes Replication controller deletion
  • Can we achieve Consul loadbalancing without haproxy?
  • $ curl -X PUT 'Hello world ' 127.0.0.1:8500/v1/kv/msg1
    $ curl 127.0.0.1:8500/v1/kv/msg1?raw
    Hello world 
    

    I then start registartor container, following one of the tutorials:

    $ sudo docker run -d --name registrator-consul -v /var/run/docker.sock:/tmp/docker.sock \
    -h jacobian-VirtualBox gliderlabs/registrator \
    -ip 127.0.0.1 consul://127.0.0.1:8500
    

    Wnen I run the above command, I get some big key in the console:

    a25a48 ... 3b69
    

    Everything looks good, since I get no error messages. If however I check

    $ docker ps
    

    I see no active images

    But at the same time, if I run

    $ docker ps -a
    

    I see this row at the very top:

    CONTAINER ID    ...    STATUS
    
    ##somecode##    ...    Exited(1) 52 seconds ago
    

    This is exactly registrator-consul container and what I do not like is that it exited. I did not do it myself, so it is really strange that it is not in active state.

    I finally build and run my php-apache container:

    $ docker build -t php-apache.
    $ docker run -d --name php-apache -p 8181:80 php-apache
    

    At this moment, everything works great. I can even check that my service is working. So, when I go to localhost:8181, I see a nice page rendered with Apache web server. BUT. My task is to check whether it was registered in Consul or not. I check it like so:

    $ curl jacobian-VirtualBox:8500/v1/catalog/services | jq '.'
    

    But as a result of this command I see this in the console:

    {
        "consul": []
    }
    

    So, no services were registered. My question is why? What I did wrong and how can I fix it? Thanks!

  • Right way to use ENTRYPOINT to enable container start and stop
  • Product Versioning Microservices
  • docker-compose copies files as folder
  • Mounting host volume for mongo data in docker compose container
  • Unknown filesystem type on /dev/mapper/docker-202
  • Docker - maven connect to specific repository in runtime
  • One Solution collect form web for “Unable to register Docker service with Registrator”

    You run your registrator with -h param. -h – just hostname for your container, not host where it will be deployed. Also you pass 127.0.0.1 as your Consul server address to registrator. 127.0.0.1 is loopback interface for registrator container – not for your host with running Consul server. If your Consul server running on your host (if you can access it by 127.0.0.1:8500) then you need to add --net=host param to your registrator run.

    P.S. I don’t know real address of jacobian-VirtualBox host that you are using in curl request. In the case if it’s not 127.0.0.1 it will not work and your need to connect your registrator container with Consul service other way (connect to other net or specify other Consul server address if it’s available inside registrator container.

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