user5616242
user5616242

Reputation:

No alive nodes found in your cluster | connection refused (Docker, PHP)

UPDATED INFO

With dd($clientBuilder->transport->getLastConnection()->getLastRequestInfo());

I could log out the following

    "curl" => array:2 [
      "error" => "Failed to connect to localhost port 30003: Connection refused"

But the thing is Elasticsearch is available under localhost:30003 via the web browser

The sample output when reaching this site:

{

    "name": "xyz",
    "cluster_name": "docker-cluster",
...
}

I did configure the host

        $clientBuilder = ClientBuilder::create()
            ->setHosts(['http://localhost:30003/'])
            ->build();

When I dd($clientBuilder), the host is set to localhost:30003

          #serializer: SmartSerializer {#385 …}
          #transportSchema: "http"
          #host: "localhost:30003"
          #path: "/"

Again, the server is up and running, I can reach it via the web browser but I still get the error message:

No alive nodes found in your cluster

In my docker-compose file, I'm mapping the port 30003 to 9200

      ports:
        - "30003:9200"

Upvotes: 1

Views: 1884

Answers (1)

user5616242
user5616242

Reputation:

Elasticsearch did not cause the error.

cURL had an error 7 which means that it could not establish a connection.

My solution I came up with was the following:

        $clientBuilder = ClientBuilder::create()
            ->setHosts([
                [
                    'host' => 'docker.for.mac.localhost',
                    'port' => '30003'
                ]
            ])
            ->build();

I switched from localhost to docker.for.mac.localhost

This helped because I'm using docker container and each container has a different ip adress

Upvotes: 1

Related Questions