5 Replies Latest reply on Jun 15, 2017 9:47 AM by sea_shankar

    trouble connecting hotrod client to docker container

    sea_shankar

      I am running a docker container for a custom domain configuration and am able to get the docker container to run.

       

      I see the hotrod server listing on the following: 174.20.0.2:11222.

       

      However, I can't get my client to connect to it, I get org.infinispan.client.hotrod.exceptions.TransportException: Could not connect to server: /174.20.0.2:11222  I am unable to telnet or ping the address.

       

      When I do the following command: docker inspect --format '{{ .NetworkSettings.IPAddress }}' $(docker ps -q),

      I don't get an address.

       

      I am guessing this is the wrong address I am connecting to.  I am using a Mac.  Bit new to docker, so confused as to which address I use.  I am running in bridge mode and have port mapped 11222.

        • 1. Re: trouble connecting hotrod client to docker container
          galder.zamarreno

          I've also have a mac and in general, I've found I can't connect to internal IP addresses from outside docker. I'm not an expert of docker but you can find information here.

           

          Now, even if you could access Hot Rod from outside the docker container, it's a bit more tricky due to the topology information that the server sends to the client. Sebastian, one of the Infinispan developers, have been working on a solution to make this easier (see here). That solution is not yet usable in an official release though.

           

          So, my general recommendation is that if you want to access Infinispan remotely via Hot Rod, you do it from within docker itself. So, have your application that uses Java Hot Rod client running inside docker. Then, maybe have a way for your application to expose a route or some HTTP entry point to the outside. When you do that, it all works fine.

           

          We have a list of demos here, but the one that uses Java Hot Rod client from within a docker container to talk to Infinispan server is this one

          • 2. Re: trouble connecting hotrod client to docker container
            galder.zamarreno

            Btw, one final thing: from what I remember, on a mac, docker ports are exposed externally. So, if you need to address in docker on port 1234, I think you can get to it by accessing it from outside on localhost:1234. Another of my colleagues, Gustavo, is more knowledgable on this particular topic even if he does not run mac.

            • 3. Re: trouble connecting hotrod client to docker container
              gustavonalle

              Are you using Docker for Mac or Docker Machine (the one who needs a virtual machine)?

               

              With Docker for Mac, it's not possible to access the container from outside using the IP (more details here) but if you using Docker Machine (on a Mac) you can add a route to the docker machine IP and then the access will work.

              • 4. Re: trouble connecting hotrod client to docker container
                gustavonalle

                Here are the steps with Docker Machine:

                 

                1) Make sure you have docker already, check with 'docker -v'

                 

                2) Run the machine installer

                 

                curl -L https://github.com/docker/machine/releases/download/v0.12.0/docker-machine-`uname -s`-`uname -m` >/usr/local/bin/docker-machine && \
                  chmod +x /usr/local/bin/docker-machine

                 

                3) Create the default machine:

                 

                docker-machine create default

                 

                4) Set the shell

                 

                eval $(docker-machine env default)

                 

                5) Run the container

                 

                docker run -it jboss/infinispan-server

                 

                6) Infinispan will print  something like

                 

                09:44:13,364 INFO  [org.infinispan.server.endpoint] (MSC service thread 1-1) DGENDPT10001: HotRodServer listening on 172.17.0.2:11222

                 

                7) Add the route

                 

                sudo route -n add 172.17.0.0/16 `docker-machine ip default`

                 

                 

                Now you can access the server by IP directly, you can test with telnet:

                 

                ➜  ~ telnet 172.17.0.2 11222

                Trying 172.17.0.2...

                Connected to 172.17.0.2.

                Escape character is '^]'.

                • 5. Re: trouble connecting hotrod client to docker container
                  sea_shankar

                  I found this other thread that seemed to help as I am not using Docker Machine:

                   

                  jboss/Infinispan-server Docker image hotrod client issues

                   

                  I added this entry:

                  <hotrod-connector socket-binding="hotrod" cache-container="clustered">

                                      <topology-state-transfer external-host="localhost" external-port="11222" lazy-retrieval="false" lock-timeout="1000" replication-timeout="5000"/>

                                  </hotrod-connector>

                   

                  This allowed me to connect on the Mac.  This is fine for me as the Mac is only used for local development.  On Linux, this seems to be working without having to put an external host and external port.  I am able to telnet 172.17.0.2 11222 there. 

                   

                  Also found that if I want to connect without using 172.17.0.2 and instead use the linux box hostaddress:11222 I need to put external-host and external port or it will keep trying to connect to 172.17.0.2.

                   

                  Thanks for the help!