Search code examples
dockerelasticsearchmagentomagento2

Elasticsearch setup for magento2 on docker gives "no alive nodes" error


I'm new to both docker and magento and I'm trying to install Magento2 on docker.

I get the error: ´Unable to connect ElasticSearch server : No alive nodes found in your cluster´

enter image description here

I tried several solutions from google searching with the text from the error.

In my "docker-compose.yml" I tried using --elasticsearch-host='127.0.0.1' --elasticsearch-port='81' instead of --elasticsearch-host='es01'

Here is my docker-compose.yml

version: '3'
services:
    web:
        image: webdevops/php-apache-dev:7.4
        container_name: web
        restart: always
        user: application
        environment:
          - WEB_ALIAS_DOMAIN=local.xxx.dk
          - WEB_DOCUMENT_ROOT=/app/pub
          - PHP_DATE_TIMEZONE=EST
          - PHP_DISPLAY_ERRORS=1
          - PHP_MEMORY_LIMIT=2048M
          - PHP_MAX_EXECUTION_TIME=300
          - PHP_POST_MAX_SIZE=500M
          - PHP_UPLOAD_MAX_FILESIZE=1024M
        volumes:
          - /Users/jonasborneland/Documents/magento:/app:cached
        ports:
          - "80:80"
          - "443:443"
          - "32823:22"
        links:
          - mysql
    mysql:
        image: mariadb:10.4
        container_name: mysql
        restart: always
        ports:
          - "3306:3306"
        environment:
          - MYSQL_ROOT_PASSWORD=root
          - MYSQL_DATABASE=magento
        volumes:
          - db-data:/var/lib/mysql
    phpmyadmin:
        container_name: phpmyadmin
        restart: always
        image: phpmyadmin/phpmyadmin:latest
        environment:
          - MYSQL_ROOT_PASSWORD=root
          - PMA_USER=root
          - PMA_PASSWORD=root
        ports:
          - "8080:80"
        links:
          - mysql:db
        depends_on:
          - mysql
    es01:
        image: docker.elastic.co/elasticsearch/elasticsearch:7.6.2
        container_name: es01
        environment:
          - node.name=es01
          - cluster.name=es-docker-cluster
          - cluster.initial_master_nodes=es01
          - bootstrap.memory_lock=true
          - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
        ulimits:
          memlock:
            soft: -1
            hard: -1
        volumes:
          - data01:/usr/share/elasticsearch/data
        ports:
          - 9200:9200
        networks:
          - elastic
volumes:
    db-data:
        external: false
    data01:
        driver: local
networks:
    elastic:
        driver: bridge

Here's the file I use inside the web container to setup magento, which results in the error:

php bin/magento setup:install \
--admin-firstname=JJ \
--admin-lastname=xxx \
--admin-email=xxx@xxx.com \
--admin-user=admin \
--admin-password='xxx!' \
--base-url=https://local.xxx.dk \
--base-url-secure=https://local.xxx.dk \
--backend-frontname=admin \
--db-host=mysql \
--db-name=magento \
--db-user=root \
--db-password=root \
--use-rewrites=1 \
--language=da_DK \
--currency=DKK \
--timezone=Europe/Copenhagen \
--use-secure-admin=1 \
--admin-use-security-key=1 \
--session-save=files \
--use-sample-data \
--elasticsearch-host=127.0.0.1 \
--elasticsearch-port=9200 \
--elasticsearch-username=admin \
--elasticsearch-password=xxx


Solution

  • I would add

    web:
        ....
        network:
         - eslastic
    es01:
        ....
        environment:
          - "discovery.type=single-node"
    
    

    prefer to this: https://github.com/markshust/docker-magento/blob/master/compose/docker-compose.yml

    as for setup:install, do:

        ....
        --elasticsearch-host=es01
        --xxxx