Hướng dẫn Setup ElasticSearch with ElasticPress trên Docker

12th Mar 2022
Table of contents

Elastic Search already has docker image available. So lets use that Docker image to setup elastic search with WordPress.

Step 1: Install docker

https://docs.docker.com/engine/installation/linux/ubuntulinux/

Step 2: Create an Elastic Search container

docker run -d -v "/var/esdata":/usr/share/elasticsearch/data elasticsearch

Repo url: https://hub.docker.com/_/elasticsearch/

Step 3: Note docker container ID

^_^[root@localhost:~]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED              STATUS              PORTS                NAMES
763fd2ca5532        elasticsearch       "/docker-entrypoint.s"   About a minute ago   Up About a minute   9200/tcp, 9300/tcp   silly_bohr

Step 4: Note container’s Private IP

^_^[root@localhost:~]# docker inspect {container id}

You will get output something like below:

"Gateway": "172.17.0.1",
"IPAddress": "172.17.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
...

Step 5: Start Elastic Search Service

First lets get a shell access to our docker container

docker exec -t -i 763fd2ca5532 /bin/bash

on second step check elastic search services status and start if not running.

root@763fd2ca5532:~# service elasticsearch status

elasticsearch is not running ... failed!

root@763fd2ca5532:~# service elasticsearch start

Starting Elasticsearch Server:sysctl: setting key "vm.max_map_count": Read-only file system.

root@763fd2ca5532:~# service elasticsearch status

elasticsearch is running.

Now lets get out of docker shell:

Check elastic search status from outside.

^_^[root@localhost:~]# curl http://{Container_IP}:9200
{
"name" : "Bandit",
"cluster_name" : "elasticsearch",
"version" : {
"number" : "2.3.3",
"build_hash" : "218bdf10790eef486ff2c41a3df5cfa32dadcfde",
"build_timestamp" : "2016-05-17T15:40:04Z",
"build_snapshot" : false,
"lucene_version" : "5.5.0"
},
"tagline" : "You Know, for Search"
}

Step 6 : Install ElasticPress plugin on wordpress

Install this plugin on your wordpress site – https://github.com/10up/ElasticPress

Add something like this on your wp-config.php. Replace {container_ip} with your docker ip.

define( 'EP_HOST', 'http://{container_ip}:9200' );

Run indexing for first time from web setting or use below wp-cli command :

wp elasticpress index

Check Elastic Search STATUS:

curl http://{container_ip}:9200/_stats
Bạn thấy bài viết này như thế nào?
0 reactions

Add new comment

Image CAPTCHA
Enter the characters shown in the image.
Câu nói tâm đắc: “Điều tuyệt với nhất trong cuộc sống là làm được những việc mà người khác tin là không thể!”

Related Articles

Trong blog CI-CD CHO DỰ ÁN CỦA BẠN mình đã giới thiệu về CI-CD và apply Gitlab CI vào dự án của bạn.

Xin chào các bạn, mình đã trở lại với bài viết chia sẻ đầu tiên về kiến thức lập trình. Như những chia sẻ ở phần giới thiệu bản thân, mình là một coder

Docker becomes more and more suitable for personal environments, especially with private servers, which can be migrated very often.

Now, I didn’t publish the service on any port. I will, in fact, add another service that will serve as our management interface of the database, phpmyadmin:

Docker provides a single command that will clean up any resources — images, containers, volumes, and networks — that are dangling (not tagged or associated with a container):