0

I am trying to run Magneto 2.4.3(php 7.4). Here is my docker-compose.yml file.

 services:
  web:
    image: webdevops/php-apache-dev:7.4
    container_name: magento2-web
    volumes:
      - .:/public_html
    ports:
      - "127.0.0.1:8989:80"
    user: www-data:www-data
    environment:
      - WEB_DOCUMENT_ROOT=/public_html/pub
      - WEB_ALIAS_DOMAIN=local.magento2.com:8989
      - WEB_NO_CACHE_PATTERN=\\.\\w+\$
      - CONTAINER_UID=33 #see https://github.com/webdevops/Dockerfile/issues/226
    restart: always
  redis:
    image: redis:latest
    container_name: magento2-redis
    ports:
      - "127.0.0.1:6379:6379"
    restart: always
  db:
    image: mariadb:10.4
    container_name: magento2-db
    command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW
    volumes:
      - magentodb:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=root
      - MYSQL_DATABASE=magento
      - MYSQL_USER=app
      - MYSQL_PASSWORD=app
    ports:
      - "127.0.0.1:3320:3306"
    restart: always
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.9.3
    container_name: magento2-elasticsearch
    volumes:
      - magentoelasticsearch:/usr/share/elasticsearch/data
    ports:
      - "127.0.0.1:9200:9200"
    environment:
      - discovery.type=single-node
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    restart: always
volumes:
  magentodb:
  magentoelasticsearch:

After bringing the docker container up and running. I ran composer install, and all the dependencies got install. As this is a legacy project I need to import the db dumb. Onces it was done. I ran the following command.

update core_config_data set value='http://magento.local:8989' where path='web/unsecure/base_url';
    
update core_config_data set value='http://magento.local:8989' where path='web/secure/base_url';
    
update core_config_data set value='magento.local:8989' where path='system/full_page_cache/varnish/access_list';


update core_config_data set value='magento.local:8989' where path='system/full_page_cache/varnish/backend_host';

Then to install Magento I run.

docker compose exec -w /public_html web php bin/magento setup:install --base-url=http://magento.local --db-host=db --db-name=magento --db-user=app --db-password=app --backend-frontname=testaf24  --search-engine=elasticsearch7  --elasticsearch-host=localhost --elasticsearch-port=9200.

But I am getting an error. Unable to connect ElasticSearch server: No alive nodes found in your cluster Following this thread. I updated the config of Elasticseach to in db and this is how it look like.

catalog/search/elasticsearch7_server_hostname       | magento2-elasticsearch
catalog/search/elasticsearch7_server_port           | 9200                                                                                      
catalog/search/elasticsearch7_index_prefix          | magento2                                                                                  
catalog/search/elasticsearch7_enable_auth            | 0                                                                                         
catalog/search/elasticsearch7_server_timeout        | 15                                                                                        
catalog/search/elasticsearch7_minimum_should_match  | NULL                                                                                      
catalog/custom_options/use_calendar                 | 0                                                                             
catalog/custom_options/year_range                   | ,

But still getting the same error.

9
  • Do hit magento.local:9200 in browser to find that Elasticsearch is installed or not
    – Kareem k
    Commented Jul 5 at 11:40
  • magento.local:9200 is not working as of right now I thought it might be because I haven't been able to install Magento yet. But 127.0.0.1:9200 is working as expected.
    – Prashant
    Commented Jul 5 at 11:45
  • try this command docker compose exec -w /public_html web php bin/magento setup:install --base-url=magento.local --db-host=db --db-name=magento --db-user=app --db-password=app --backend-frontname=testaf24 --search-engine=elasticsearch7 --elasticsearch-host=elasticsearch:9200 --elasticsearch-port=9200.
    – Kareem k
    Commented Jul 5 at 11:59
  • Same error. Unable to connect ElasticSearch server : No alive nodes found in your cluster
    – Prashant
    Commented Jul 5 at 12:04
  • try this catalog/search/elasticsearch7_server_hostname | elasticsearch
    – Kareem k
    Commented Jul 5 at 12:28

1 Answer 1

0

@Prashant

Hey,

Update Docker Compose File

Your Docker Compose file is mostly correct, but ensure you have the appropriate network configuration if needed. Here's a slightly refined version of your Docker Compose file:

version: '3.7'

services:
  web:
    image: webdevops/php-apache-dev:7.4
    container_name: magento2-web
    volumes:
      - .:/public_html
    ports:
      - "127.0.0.1:8989:80"
    user: www-data:www-data
    environment:
      - WEB_DOCUMENT_ROOT=/public_html/pub
      - WEB_ALIAS_DOMAIN=local.magento2.com:8989
      - WEB_NO_CACHE_PATTERN=\\.\\w+\$
      - CONTAINER_UID=33 #see https://github.com/webdevops/Dockerfile/issues/226
    depends_on:
      - db
      - redis
      - elasticsearch
    restart: always

  redis:
    image: redis:latest
    container_name: magento2-redis
    ports:
      - "127.0.0.1:6379:6379"
    restart: always

  db:
    image: mariadb:10.4
    container_name: magento2-db
    command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW
    volumes:
      - magentodb:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=root
      - MYSQL_DATABASE=magento
      - MYSQL_USER=app
      - MYSQL_PASSWORD=app
    ports:
      - "127.0.0.1:3320:3306"
    restart: always

  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.9.3
    container_name: magento2-elasticsearch
    volumes:
      - magentoelasticsearch:/usr/share/elasticsearch/data
    ports:
      - "127.0.0.1:9200:9200"
    environment:
      - discovery.type=single-node
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    restart: always

volumes:
  magentodb:
  magentoelasticsearch:

Install Magento with Elasticsearch Configuration

When installing Magento, specify the Elasticsearch host and port. You can do this during the Magento installation process via the command line:

php bin/magento setup:install \
  --base-url=http://local.magento2.com:8989/ \
  --db-host=db \
  --db-name=magento \
  --db-user=app \
  --db-password=app \
  --backend-frontname=admin \
  --admin-firstname=Admin \
  --admin-lastname=User \
  [email protected] \
  --admin-user=admin \
  --admin-password=admin123 \
  --language=en_US \
  --currency=USD \
  --timezone=America/Chicago \
  --use-rewrites=1 \
  --search-engine=elasticsearch7 \
  --elasticsearch-host=elasticsearch \
  --elasticsearch-port=9200

Configure Magento to Use Elasticsearch

If Magento is already installed, you can configure it to use Elasticsearch with the following commands:

php bin/magento config:set catalog/search/engine elasticsearch7
php bin/magento config:set catalog/search/elasticsearch7_server_hostname elasticsearch
php bin/magento config:set catalog/search/elasticsearch7_server_port 9200
php bin/magento cache:flush

Run Docker Compose

Make sure your Docker services are up and running

docker-compose up -d

Access Magento

Open your browser and navigate to http://127.0.0.1:8989/ or http://local.magento2.com:8989/ (ensure you've set up your hosts file to point local.magento2.com to 127.0.0.1).

Feel free to ask all your queries until they are completely solved. Thank You!

2
  • I made the changes in docker.compose.yml file purge the other container, volume and network and then ran the install command still the same error "Unable to connect ElasticSearch server : No alive nodes found in your cluster"
    – Prashant
    Commented Jul 9 at 13:40
  • As mentioned earlier I am using an already running magento not installing the fresh instances of it.
    – Prashant
    Commented Jul 9 at 13:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.