Closed mnoky closed 5 years ago
Here are some more details I discovered: I am using a swarmMgrUri that looks like this: http://docker-socket-proxy_service:2375. This is the tecnativa/docker-socket-proxy running in a separate stack. Notice the underscore in the name, which is added automatically when the docker stack is deployed (stackName_serviceName). Problem is, the Java URI class doesn't like this! For example, if you run this snippet of code:
URI u1 = new URI("http://docker-socket-proxy_service:2375");
URI u2 = new URI("http://docker-socket-proxy:2375");
System.out.println("u1=" + u1 + " host=" + u1.getHost());
System.out.println("u2=" + u2 + " host=" + u2.getHost());
The result is:
u1=http://docker-socket-proxy_service:2375 host=null
u2=http://docker-socket-proxy:2375 host=docker-socket-proxy
Notice that the host is null when an underscore is used in the name! Thus, when DefaultDockerClient.listNetworks() happens, the hostname is null.
Is there any way to work around this?
It appears that this is a widespread issue with the java URI class. Although the underscore character is technically disallowed in URIs according to the RFC, it happens all the time due to docker stacks, S3 buckets, etc. The redisson project worked around this by literally hacking the URI class. This is ugly and fragile, but it works:
https://github.com/redisson/redisson/issues/1367 https://github.com/redisson/redisson/commit/dd13ac99e25f148bf24332ee1b9da096e0f9f067
Original source of workaround:
https://stackoverflow.com/questions/28568188/java-net-uri-get-host-with-underscores/28568433
Not sure if you are amenable to adding this workaround in the hazelcast-docker-swarm-discovery-spi project, but it would be helpful. For now, I can add the workaround to my code which instantiates it. In our use cases, we really want to have a single docker-socket-proxy running in a separate stack which can be leveraged by multiple different services in other stacks.
Glad you got it figured out! If you'd like to contribute a PR to address this, please do so and we can incorporate it in, or at a minimum a good note in the README covering this issue and the workaround.
It turns out the URI hack is really fragile and doesn't work well in newer versions of java. I found a better solution was to run the docker-socket-proxy using a network alias so that it can be accessed without the use of an underscore. In docker-compose.yml
:
services:
proxy-service:
networks:
my-network:
aliases:
- dockersocketproxy
This allows me to use a swarmMgrUri
of http://dockersocketproxy:2375
Hi, I'm using 1.0-RC14 and am trying to get SwarmMemberAddressProvider working. I'm using the tecnativa/docker-socket-proxy (running as a separate service, configured via swarmMgrUri) to safely proxy the docker socket. Everything seems to be configured correctly, I can see the following in the log message at startup:
However, then the following exception is generated at startup:
Not really sure what is going on or why a particular hostname is null. Can you offer some insight here?