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
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).