Skip to content

Installing Magento via docker getting with Elasticsearch

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.