Closed BogdanIrimie closed 7 years ago
Please provide more detail, sample app/config code, commands etc.
Sample app:
public class Main {
public static void main(String[] args) throws Exception {
final Config conf = new ClasspathXmlConfig("hazelcast.xml");
final NodeContext nodeContext = new DefaultNodeContext() {
@Override
public AddressPicker createAddressPicker(Node node) {
return new SwarmAddressPicker(new SystemPrintLogger());
}
};
final HazelcastInstance hazelcastInstance = HazelcastInstanceFactory
.newHazelcastInstance(conf,"hazelcast-bluesky",nodeContext);
}
}
The config file is identical to hazelcast-docker-swarm-discovery-spi-example.xml
.
The docker compose is:
version: '3.3'
services:
hazelcast:
image: hazelcast-test:1.0-SNAPSHOT
ports: ["54327:54327", "5701:5701"]
deploy:
mode: global
networks:
- hazelcast_net
networks:
hazelcast_net:
driver: overlay
The starting command is:
java -DdockerNetworkNames=hazelcast_net -DdockerServiceNames=hazelcast -DhazelcastPeerPort=5701 -DdockerServiceLabels=hazelcast -jar hazelcast-test.jar
and whats the DOCKER_HOST
env variable for the docker container
I didn't know what to use for DOCKER_HOST
so I have used the IP of the machine with docker swarm master.
DOCKER_HOST needs to point to a http accessible URI/port of a swarm manager
i.e if you can curl http://[swarmmgr]:[port]/networks
then you are good
When running curl with http://[swarmmgr]:2377/networks
I receive nothing. On port 2376 there is no process listening on the docker manager.
Please read: https://docs.docker.com/engine/reference/commandline/dockerd/#extended-description
to configure your daemon to listen on a tcp socket, or use socat
to redirect traffic to the local socket (see .travis.tml
)
The example from .travis.yml
was very useful, managed to make it work in swarm mode, thank you!
great!
@IrimieBogdan if you have a compose file sample (working w/ the example in this project) can you please post the working compose file
Socat Dockerfile:
FROM alpine:3.1
RUN apk --update add socat
ENTRYPOINT ["socat", "TCP4-LISTEN:2375,fork,reuseaddr", "UNIX-CONNECT:/var/run/docker.sock"]
Hazelcast Dockerfile:
FROM java:8u111-jre-alpine
ADD hazelcast_docker_spi.jar /home/hazelcast_docker_spi.jar
ENTRYPOINT ["java", "${JAVA_OPTS}", "-jar", "/home/hazelcast_docker_spi.jar"]
Compose file:
version: '3.3'
services:
socat-test:
image: socat-test
volumes: ["/var/run/docker.sock:/var/run/docker.sock"]
deploy:
mode: global
placement:
constraints: [node.role == manager]
networks:
test_net:
aliases: ["socat-test"]
hazelcast-test:
image: hazelcast-test
ports: ["54327:54327", "5701:5701"]
environment:
- DOCKER_HOST=http://socat-test:2375
- JAVA_OPTS=-DdockerNetworkNames=${STACK_NAME}_test_net -DdockerServiceNames=${STACK_NAME}_hazelcast-test -DhazelcastPeerPort=5701
deploy:
mode: global
networks:
- test_net
networks:
test_net:
driver: overlay
ipam:
config: [{subnet: 172.28.0.0/16}]
driver: default
STACK_NAME
is the name of the stack used with docker stack deploy ...
Exception in thread "main" java.lang.RuntimeException: SwarmAddressPicker: Error constructing SwarmDiscoveryUtil: discoverContainers() unexpected error: java.util.concurrent.ExecutionException: javax.ws.rs.ProcessingException: java.io.IOException: No such file or directory
The program was started with in docker swarm using :
java -DdockerNetworkNames=bluesky_hazelcast_net -DdockerServiceNames=hazelcast -DhazelcastPeerPort=5701 -DdockerServiceLabels=hazelcast -jar hazelcast-test.jar
and the main class is similar withDockerTestRunner.java