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/

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

  • How to connect a service running inside a docker with consul?
  • How does horizontal scaling decrease load of a system?
  • How to enable faster container rescheduling with Docker Swarm and Consul?
  • Creating docker-consul official image
  • Multiservice application in Teamcity - composing branches
  • How to make containers communicate with each other in ECS without link and port mapping?
  • $ curl -X PUT 'Hello world '
    $ curl
    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 consul://

    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:

    ##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!

  • How to use Docker to obtain JDK + MySQL + Tomcat container?
  • Docker build error There are no enabled repos
  • docker hub automated build does not use cache, does this mean layers are regenerated every time and that requires docker clients to redownload?
  • Docker Compose when to use image over build
  • ASP.NET Core EF commands: Unable to connect to any of the specified MySQL hosts
  • Connecting IBM Containers (Dockers) to Watson IoT service instance
  • 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 as your Consul server address to registrator. 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 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 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.