Failed to connect to Docker Aerospike from host

I am launching an aerospace server in docker.

$  docker run -d --name aerospike aerospike/aerospike-server
0ad3b2df67bd17f896e87ed119758d9af7fcdd9b82a8632828e01072e2c5673f

It has been successfully launched.

$docker ps
CONTAINER ID        IMAGE                        COMMAND                
CREATED             STATUS              PORTS               NAMES
0ad3b2df67bd        aerospike/aerospike-server   "/entrypoint.sh asd"    
4 seconds ago       Up 2 seconds        3000-3003/tcp       aerospike

I found the docker ip address using the command below.

$ docker inspect -f '{{.NetworkSettings.IPAddress }}' aerospike
172.17.0.2 

When I try to connect to aql using the command below, it is also successful.

$ docker run -it aerospike/aerospike-tools aql -h  $(docker inspect -f 
'{{.NetworkSettings.IPAddress }}' aerospike)
 Aerospike Query Client
 Version 3.15.0.3
 C Client Version 4.2.0
 Copyright 2012-2017 Aerospike. All rights reserved.
 aql> select * from test.person
 0 rows in set (0.002 secs)

Now I am trying to connect to the aero-testing server in the docker using the java client in the host machine.

public class AerospikeDemo {
    public static void main(String []args) {

        AerospikeClient client = new AerospikeClient("172.17.0.2", 3000);
        Key key = new Key("test", "demo", "putgetkey");
        //Key key2 = new Key("1", "2", "3");
        Bin bin1 = new Bin("bin1", "value1");
        Bin bin2 = new Bin("bin2", "value2");
        Bin bin3 = new Bin("bin2", "value3");

        // Write a record
        client.put(null, key, bin1, bin2, bin3);

        // Read a record
        Record record = client.get(null, key);

        System.out.println("record is "+ record);
        System.out.println("record bins is " + record.bins);

        client.close();
      }
  }

When I run the above program, I get below the error -

objc[3446]: Class JavaLaunchHelper is implemented in both 
/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/bin/java (0x10f7b14c0) and /Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/jre/lib/libinstrument.dylib (0x10f8794e0). One of the two will be used. Which one is undefined.
Exception in thread "main" com.aerospike.client.AerospikeException$Connection: 
Error Code 11: Failed to connect to host(s): 172.17.0.2 3000 Error Code 11: java.net.SocketTimeoutException: connect timed out

at com.aerospike.client.cluster.Cluster.seedNodes(Cluster.java:413)
at com.aerospike.client.cluster.Cluster.tend(Cluster.java:306)
at com.aerospike.client.cluster.Cluster.waitTillStabilized(Cluster.java:271)
at com.aerospike.client.cluster.Cluster.initTendThread(Cluster.java:181)
at com.aerospike.client.AerospikeClient.<init>(AerospikeClient.java:210)
at com.aerospike.client.AerospikeClient.<init>(AerospikeClient.java:151)
at com.demo.aerospike.AerospikeDemo.main(AerospikeDemo.java:12)

I tried both AerospikeClient("172.17.0.2", 3000)andAerospikeClient("localhost", 3000)

I see in Dockerfile port 3000 is open for the host, but I'm not sure why I cannot use the aerospace server in the docker.

+4
source share
1 answer

IP 172.17.0.2 Docker ( ). , .

docker run -d --name aerospike -p 3000:3000 aerospike/aerospike-server

:

AerospikeClient client = new AerospikeClient("localhost", 3000);
+4

Source: https://habr.com/ru/post/1689713/


All Articles