Documentation

Exercise: Run Liferay and Elasticsearch Using Docker

Applies to: Liferay DXP 7.3+

Here you can walk through a minimal Liferay-Elasticsearch setup on your local machine to see how the REST Client connection between Elasticsearch and Liferay DXP 7.3+ is configured. The example uses two Docker containers: one Elasticsearch container and one Liferay DXP container. For more conceptual and production-like information see Installing Elasticsearch.

Read Securing Elasticsearch to enable authentication and encryption on the Elasticsearch connection.

Create Local Folders for Bind Mounting to the Docker Containers

Create a local folder structure that can be bind mounted to the Elasticsearch and DXP containers’ system folders for providing plugins and configuration files:

mkdir -p test-es-install/dxp/files/osgi/configs && mkdir -p test-es-install/elasticsearch && cd test-es-install

Tip

The cd test-es-install command at the end puts you in the test-es-install folder. Make sure you run the remaining commands for both Elasticsearch and Liferay DXP from this folder.

Install Elasticsearch

  1. Configure and start an Elasticsearch 7.17.4 container named elasticsearch717:

    docker run -it --name elasticsearch717 -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e "node.name=es-node1" -v $(pwd)/elasticsearch:/usr/share/elasticsearch/data docker.elastic.co/elasticsearch/elasticsearch:7.17.4
    
  2. Install the required Elasticsearch plugins. Use docker exec -it to access an interactive bash shell:

    docker exec -it elasticsearch717 bash -c '/usr/share/elasticsearch/bin/elasticsearch-plugin install analysis-icu && /usr/share/elasticsearch/bin/elasticsearch-plugin install analysis-kuromoji && /usr/share/elasticsearch/bin/elasticsearch-plugin install analysis-smartcn && /usr/share/elasticsearch/bin/elasticsearch-plugin install analysis-stempel'
    
  3. Restart the Elasticsearch container to register the plugins. CTRL+C stops the container, then start it again by running

    docker start -i elasticsearch717
    
  4. Get the IPv4 address of the running Elasticsearch container:

    docker network inspect bridge
    

    In this example it’s 172.17.0.2. If your system provides a different IP address, you must use it in the docker run --add-host elasticsearch717:[IP]... command when running Liferay DXP.

    "Containers": {
                "2d4614fdcce2159322fa7922bfc5f866b79bd7f609a65cc888f9a260f80731f4": {
                    "Name": "elasticsearch717",
                    "EndpointID": "e89c3d0a87cc528753470eb359cee3b85fea9f9a5df3b249d54d203741a650a8",
                    "MacAddress": "02:42:ac:11:00:02",
                    "IPv4Address": "172.17.0.2/16",
                    "IPv6Address": ""
                }
            },
    

Install Liferay DXP

Specify the properties Liferay DXP needs to connect with Elasticsearch, then run the DXP container.

  1. First populate the Elasticsearch 7 configuration file by running

    cat <<EOT >> dxp/files/osgi/configs/com.liferay.portal.search.elasticsearch7.configuration.ElasticsearchConfiguration.config
    
    operationMode="REMOTE"
    productionModeEnabled=B"true"
    networkHostAddresses="http://elasticsearch717:9200"
    EOT
    
  2. Once the configuration files are in place, start the DXP container with

    docker run -it --name dxp74  --add-host elasticsearch717:172.17.0.2 -p 8080:8080 -v $(pwd)/dxp:/mnt/liferay liferay/portal:7.4.3.47-ga47
    
  3. Checkpoint: Verify that the Elasticsearch connection is active in Control Panel → Configuration → Search.

    An active connection is displayed in the Search administrative panel.

Re-index your search and spell check indexes. Both re-index actions are carried out from the Index Actions tab of Control Panel → Configuration → Search.

Additional Information