0
votes

I am trying to setup docker for an already existing laravel project. As you guys know Laravel Scout provides a simple, driver based solution for adding full-text search to our Eloquent models, I use it in my own project. I use laradock and install elasticsearch as a driver for scout. However, when I attempt to create index php artisan elastic:create-index App\\MyIndexConfigurator (or even scout import command) it has this error No alive nodes found in your cluster.

The strange thing is, if I got to http://localhost:9200/_cluster/health, it looks fine:

`{
  cluster_name: "laradock-cluster",
  status: "green",
  timed_out: false,
  number_of_nodes: 1,
  number_of_data_nodes: 1,
  active_primary_shards: 0,
  active_shards: 0,
  relocating_shards: 0,
  initializing_shards: 0,
  unassigned_shards: 0,
  delayed_unassigned_shards: 0,
  number_of_pending_tasks: 0,
  number_of_in_flight_fetch: 0,
  task_max_waiting_in_queue_millis: 0,
  active_shards_percent_as_number: 100
}`

It is my scout_elastic config:

return [
    'client' => [
        'hosts' => [
            env('SCOUT_ELASTIC_HOST', 'localhost:9200'),
        ],
    ],
    'update_mapping' => env('SCOUT_ELASTIC_UPDATE_MAPPING', true),
    'indexer' => env('SCOUT_ELASTIC_INDEXER', 'single'),
    'document_refresh' => env('SCOUT_ELASTIC_DOCUMENT_REFRESH'),
];

and here it is my docker-compose.yml:

### ElasticSearch ########################################
    elasticsearch:
      build: ./elasticsearch
      volumes:
        - elasticsearch:/usr/share/elasticsearch/data
      environment:
        - cluster.name=laradock-cluster
        - node.name=laradock-node
        - bootstrap.memory_lock=true
        - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
        - cluster.initial_master_nodes=laradock-node
      ulimits:
        memlock:
          soft: -1
          hard: -1
      ports:
        - "${ELASTICSEARCH_HOST_HTTP_PORT}:9200"
        - "${ELASTICSEARCH_HOST_TRANSPORT_PORT}:9300"
      depends_on:
        - php-fpm
      networks:
        - frontend

- backend

Edit:

curl -XGET http://elasticsearch:9200/_cluster/health :

{
"cluster_name":"laradock-cluster","status":"green",
"timed_out":false,
"number_of_nodes":1,
"number_of_data_nodes":1,
"active_primary_shards":0,
"active_shards":0,
"relocating_shards":0,
"initializing_shards":0,
"unassigned_shards":0,
"delayed_unassigned_shards":0,
"number_of_pending_tasks":0,
"number_of_in_flight_fetch":0,
"task_max_waiting_in_queue_millis":0,
"active_shards_percent_as_number":100.0
}

.env:

APP_NAME=Laravel
APP_ENV=local
APP_DEBUG=true
APP_URL=http://127.0.0.1

SCOUT_DRIVER=elastic
SCOUT_ELASTIC_HOST=elasticsearch:9200
1
Try to change hosts definition in config to env('SCOUT_ELASTIC_HOST', 'elasticsearch:9200') Your Laravel app is runned inside container, and localhost is address of this container, not your host machine.maximkou
tnx for your reply @maximkou, I use elasticsearch:9200 and even host.docker.internal:9200 as internal host none of them aren't worked...k90mirzaei
Do you run create-index from your host machine or from docker container? You must call this from container and use elasticsearch:9200 inside your app config.maximkou
I actually just run ../laradock>docker-compose exec workspace bash and then create-indexk90mirzaei
Thanks, can you run artisan config:clear before calling create-index (maybe your configs is cached and app requests old host)?maximkou

1 Answers

0
votes

You need to change SCOUT_ELASTIC_HOST

It should be SCOUT_ELASTIC_HOST=http://elasticsearch:9200 Not http://localhost:9200