Docker - oracle.kv.FaultException: Could not conta

2019-09-10 03:22发布

问题:

I am new to Docker and nosql, I created a Oracle Linux VM (ipAddr 192.168.10.2) on my windows machine.

Further I created docker container (on this VM ) for kvlite and run my nosql-container as below:

$ docker run --name nosql-container -p 5000:5000 -d kvlite:latest

followed by below commands:

$ docker exec -it nosql-container bash

# java -jar lib/kvcli.jar -host localhost -port 5000

kv-> connect store -host localhost -port 5000 -name kvstore ;

This works fine till here and I believe my Docker container for kvlite is up and running fine.

Now I need to create a Client Java program from my windows machine to access this kvlite (running in docker container on a VM) To accomplish I downloaded kvclient.jar file and put that in my classpath.

The Java code-snippet below:

KVStore store = KVStoreFactory.getStore(new KVStoreConfig("kvstore", "192.168.10.2:5000"));

This throws an exception:

oracle.kv.FaultException: Could not contact any RepNode at: [192.168.10.2:5000] (12.1.4.0.9)

....

Caused by: java.rmi.UnknownHostException: Unknown host: ecfe59938ea4; nested exception is:

Any help appreciated in advance.

回答1:

I resolved the issue by adding a param --net=host when running nosql-container

$ docker run --name nosql-container --net=host -p 5000:5000 -d kvlite:latest

Now instead of IPAddress you can use VM hostname in Java Client code to access kvlite DB.

KVStore store = KVStoreFactory.getStore(new KVStoreConfig("kvstore", "VMHostname:5000"));