-1

I have a go-micro service, and I want it to register at a Consul running in a container. When doing this just from the command prompt, this runs fine. I check the logs from the consul-container and see everything is okay. Registering and deregistering:

 2018/08/06 08:54:44 [WARN] agent: Service name "myservice.ucum-service" will not be discoverable via DNS due to invalid characters. Valid characters include all alpha-numerics and dashes.
 2018/08/06 08:54:44 [INFO] agent: Synced service "myservice.ucum-service-5d4543b5-9956-11e8-a484-5404a6f49407"
 2018/08/06 08:54:44 [INFO] agent: Synced check "service:myservice.ucum-service-5d4543b5-9956-11e8-a484-5404a6f49407"
 2018/08/06 08:54:53 [INFO] agent: Deregistered service "myservice.ucum-service-5d4543b5-9956-11e8-a484-5404a6f49407"
 2018/08/06 08:54:53 [INFO] agent: Deregistered check "service:myservice.ucum-service-5d4543b5-9956-11e8-a484-5404a6f49407"

As you can see, it complains about invalid characters. I don't know what it means, but it runs fine, I can run my tests from the service-client without problem. So we can assume that the Consul-container runs fine.

But now my question. I want to run the service also in a container, and there a problem occurred. This is my Dockerfile for the service:

FROM debian:stretch
MAINTAINER Bert Verhees "xxxxx@xxxxx.xx"
ADD archibold_ucum_service /archibold_ucum_service
ADD data/ucum-essence.xml /data/ucum-essence.xml
ENTRYPOINT ["/archibold_ucum_service", "-ucumfile=/data/ucum-essence.xml"]

As you can see, the service needs to start with a parameter, also that is no problem.

When I start this container, it seems to run fine, but when I look at the consul-logs, it never saw it. And the logs of the service container tell me why. I start the container in this way:

docker run -d --name=ucum_micro_service ucum_micro_service

It gets very nice a container ID. So it looks fine, but looking at the logs, this happens:

2018/08/06 09:51:42 Listening on [::]:46517
2018/08/06 09:51:42 Broker Listening on [::]:38283
2018/08/06 09:51:42 Registering node: myservice.ucum-service-52a66d2c-995e-11e8-bb3a-0242ac110002
2018/08/06 09:51:42 Put http://127.0.0.1:8500/v1/agent/service/register: dial tcp 127.0.0.1:8500: connect: connection refused

So my idea is that it is not able to break out of the container. But how can I solve this problem?

I appreciate help very much, thanks

Bert Verhees
  • 1,057
  • 3
  • 14
  • 25
  • 1
    When I've done this in the past I've used Consul health checks to find what's running on the machine, instead of having services push their own state into Consul, which mostly avoids this problem. I'm pretty sure the "invalid character" is the "." and that Consul won't serve up subdomains in its internal DNS (you can't have a `myservice.ucum-service.service.consul` DNS name). – David Maze Aug 06 '18 at 12:40
  • I had the dot-build subdomains from go-micro examples. I thought so, it was the dot, because the error message is clear about it. Now I know for sure. Thanks. I will clean that up. – Bert Verhees Aug 06 '18 at 13:55
  • I wonder who downvoted this question without any comment, and I would like to know why. I think stackoverflow should not allow that. It discourages people to be active on stackoverflow. – Bert Verhees Oct 26 '18 at 05:55

1 Answers1

1

Unless you use --network=host in your docker run command, localhost in your container is not the same as localhost on your machine. Just like docker creates a "separate" filesystem for your container it does the same with network.

So either you use docker run --network=host -d --name=ucum_micro_service ucum_micro_service, you run the other service also in a container and use docker networks / links or similar to connect them, or you use the public ip of your machine (which you could pass as a argument).

herm
  • 14,613
  • 7
  • 41
  • 62