L
L
Lenskiy-e2019-06-30 21:05:58
elasticsearch
Lenskiy-e, 2019-06-30 21:05:58

Why might the “No alive nodes found in your cluster” error occur when using Laravel and Docker Elasticsearch?

Can't make laravel and elasticsearch friends using Docker and `babenkoivan/scout-elasticsearch-driver` .
When I start Docker, all containers, including elasticsearch, start fine, but when I try to enter:

php artisan elastic:create-index "App\TutorialIndexConfigurator"

I get an error:
No alive nodes found in your cluster
Also, when I try to request project port 9200 via curl in the docker workspace container, I get
curl: (7) Failed to connect to localhost port 9200: Connection refused

at the same time, if you make the same request from the terminal, then I get a response from elasticsearch with json data, that is, everything is ok. I think the main problem is somehow related to this.
I tried to run the same containers with laradock - the result is the same.
I have been fighting for 3 days and giving up, so I beg you to help me.
Here is my docker-compose.yml
spoiler

version: '3.1'
    
    #volumes:
    #  elasticsearch:
    #    driver: local
    
    volumes:
      esdata1:
        driver: local
      esdata2:
        driver: local
      esdata3:
        driver: local
    
    networks:
      esnet:
      frontend:
      backend:
    
    services:
      nginx:
        image: nginx
        ports:
            - "80:80"
            - "443:443"
        volumes:
          - ./hosts:/etc/nginx/conf.d
          - ./www:/var/www
          - ./logs:/var/log/nginx
        links:
          - php
        networks:
          esnet:
          frontend:
            aliases:
              - api.dev
          backend:
            aliases:
              - api.dev
    
      mysql:
        image: mysql:5.7
    
        ports: 
        - "3306:3306"
    
        volumes:
          - ./mysql:/var/lib/mysql
    
        environment:
            MYSQL_ROOT_PASSWORD: secret
    
        networks:
          - esnet
          - frontend
          - backend
    
      # postgres:
      #   image: postgres
    
      #   ports: 
      #     - "3306:3306"
    
      #   environment:
      #       MYSQL_ROOT_PASSWORD: secret
    
      adminer:
        image: adminer
        restart: always
        ports:
          - 8080:8080
    
      php:
        build: ./images/php
    
        links:
          - mysql
    
        volumes:
          - ./www:/var/www
    
        networks:
          - esnet
          - frontend
          - backend
    
      workspace:
          build: ./images/workspace
          volumes:
            - ./www:/var/www:cached
          extra_hosts:
            - "dockerhost:10.0.75.1"
          ports:
            - "2222:22"
          tty: true
          networks:
            - esnet
            - frontend
            - backend
    
      redis:
        image: redis:latest
    
        volumes:
              - ./www/redis:/data
    
        ports:
          - "6379:6379"
    
    
      elasticsearch:
        image: docker.elastic.co/elasticsearch/elasticsearch:6.4.2
        container_name: elasticsearch
        environment:
          - cluster.name=docker-cluster
          - bootstrap.memory_lock=true
          - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
          - http.cors.enabled=true
          - http.cors.allow-origin=*
          - discovery.zen.minimum_master_nodes=2
        ulimits:
          memlock:
            soft: -1
            hard: -1
        volumes:
          - esdata1:/usr/share/elasticsearch/data
        ports:
          - 9200:9200
        networks:
          - esnet
          - frontend
          - backend
    
      lasticsearch2:
        image: docker.elastic.co/elasticsearch/elasticsearch:6.4.2
        container_name: elasticsearch2
        environment:
          - cluster.name=docker-cluster
          - bootstrap.memory_lock=true
          - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
          - "discovery.zen.ping.unicast.hosts=elasticsearch"
          - http.cors.enabled=true
          - http.cors.allow-origin=*
          - discovery.zen.minimum_master_nodes=2
        ulimits:
          memlock:
            soft: -1
            hard: -1
        volumes:
          - esdata2:/usr/share/elasticsearch/data
        networks:
          - esnet
          - frontend
          - backend
    
      elasticsearch3:
        image: docker.elastic.co/elasticsearch/elasticsearch:6.4.2
        container_name: elasticsearch3
        environment:
          - cluster.name=docker-cluster
          - bootstrap.memory_lock=true
          - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
          - "discovery.zen.ping.unicast.hosts=elasticsearch"
          - http.cors.enabled=true
          - http.cors.allow-origin=*
          - discovery.zen.minimum_master_nodes=2
        ulimits:
          memlock:
            soft: -1
            hard: -1
        volumes:
          - esdata3:/usr/share/elasticsearch/data
        networks:
          - esnet
          - frontend
          - backend
    
      kibana:
        image: 'docker.elastic.co/kibana/kibana:6.4.2'
        container_name: kibana
        environment:
          SERVER_NAME: kibana.local
          ELASTICSEARCH_URL: http://elasticsearch:9200
        ports:
          - '5601:5601'
        networks:
          - esnet
          - frontend
          - backend
    
      headPlugin:
        image: 'mobz/elasticsearch-head:5'
        container_name: head
        ports:
          - '9100:9100'
        networks:
          - esnet
          - frontend
          - backend


Also 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 .env scout configSCOUT_DRIVER=elastic

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
N, 2019-08-20
@Fernus


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'),
    ];

Replace localhost with elasticsearch ...

R
romanown, 2019-08-17
@romanown

curl: (7) Failed to connect to localhost port 9200: Connection refused means elasticsearch is not available. as an option for the reason that it is not running. but it may not work for various reasons. First of all, make sure that Elasticsearch is running and listening on the correct addresses and ports. commands depend on the operating system you are using.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question