Search code examples
macosdockernuodb

NuoDB setup on Docker for MacOS. Connection to NuoDB failed. [08S01] Could not connect to any host


I have set up NuoDB locally using docker image. It works fine and I can access a database console and run queries by accessing http://localhost:8888/explorer.jsp. But when I'm trying to connect to the database using JDBC I got error:

Connection to NuoDB failed. [08S01] Could not connect to any host [localhost]. Errors are [java.io.IOException: Operation time out (Connection time out), /172.17.0.3:48006]

As I understand I have successfully connect to NuoDB broker by localhost:48004. And After the broker throws me to the database node address 172.17.0.3:48006 where 172.17.0.3 is IP of running docker container that is not accessible from host due to the limitation described at official documentation.

My question is how can I connect to the database? Are there any workarounds?

Here is my env:
Docker version 17.03.1-ce, build c6d412e.
I run container by command:
docker run -d --privileged=true -p 48004:48004 -p 48005:48005 -p 48006:48006 -p 9001:9001 -p 8888:8888 nuodb-test.
Dockerfile and NuoDB setup could be found in my github repo.

Thanks in advance.


Solution

  • I figure out this problem. The solution is next.

    1) set up Docker Toolbox. It comes with VirtualBox VM and you will be able to use VM ip address to connect to DB.

    Below described a set of commands to run NuoDB under Docker Toolbox.
    2) Run eval $(docker-machine env default) for switching to Docker Toolbox.
    For switching back to Docker for MacOS run unset ${!DOCKER_*}.

    3) Start container with options --network=host -e BROKER_ALT_ADDR=$(docker-machine ip).
    In my case full command is:
    docker run -d --privileged=true --network=host -e BROKER_ALT_ADDR=$(docker-machine ip) -p 48004:48004 -p 48005:48005 -p 48006:48006 -p 9001:9001 -p 8888:8888 nuodb-test

    4) Use docker-machine ip command to get your default docker machine IP address. Now you are able to connect by this ip. JDBC connection string example: jdbc:com.nuodb://192.168.99.100/test where 192.168.99.100 is docker machine IP address.

    As well you are able to connect to database Admin Center by IP http://192.168.99.100:8888/.

    For more information read docs