bitsofinfo / hazelcast-docker-swarm-discovery-spi

Docker Swarm based discovery strategy SPI for Hazelcast enabled applications
Apache License 2.0
39 stars 33 forks source link

Error when starting the service via docker compose #1

Closed BogdanIrimie closed 7 years ago

BogdanIrimie commented 7 years ago

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 with DockerTestRunner.java

bitsofinfo commented 7 years ago

Please provide more detail, sample app/config code, commands etc.

BogdanIrimie commented 7 years ago

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
bitsofinfo commented 7 years ago

and whats the DOCKER_HOST env variable for the docker container

BogdanIrimie commented 7 years ago

I didn't know what to use for DOCKER_HOST so I have used the IP of the machine with docker swarm master.

bitsofinfo commented 7 years ago

DOCKER_HOST needs to point to a http accessible URI/port of a swarm manager

bitsofinfo commented 7 years ago

i.e if you can curl http://[swarmmgr]:[port]/networks then you are good

BogdanIrimie commented 7 years ago

When running curl with http://[swarmmgr]:2377/networks I receive nothing. On port 2376 there is no process listening on the docker manager.

bitsofinfo commented 7 years ago

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)

BogdanIrimie commented 7 years ago

The example from .travis.yml was very useful, managed to make it work in swarm mode, thank you!

bitsofinfo commented 7 years ago

great!

bitsofinfo commented 7 years ago

@IrimieBogdan if you have a compose file sample (working w/ the example in this project) can you please post the working compose file

BogdanIrimie commented 7 years ago

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