제공괴는 Image에 추가로 몇몇 플러그인등을 적용해야하니 별도의 Dockerfile을 작성한다.
$> vi Dockerfile
# Elasticsearch 6.5.4
FROM docker.elastic.co/elasticsearch/elasticsearch:6.5.4
WORKDIR /usr/share/elasticsearch
RUN /usr/share/elasticsearch/bin/elasticsearch-plugin install --batch discovery-ec2
RUN /usr/share/elasticsearch/bin/elasticsearch-plugin install --batch analysis-nori
$> docker build -t elasticsearch-my6_5_4 .
EC2 용 플러그인과 한글 형태소 Nori를 추가했다. build 실행 후,image목록을 보면 아래와 같이 추가되어 있는 image를 볼 수 있다.
$> docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
elasticsearch-my_6_5_4 latest d21d0f522868 About a minute ago 788MB
docker.elastic.co/elasticsearch/elasticsearch 6.5.4 93109ce1d590 7 days ago 774MB
이제 docker-compose.yml를 만든다.
version: '2.2'
services:
elasticsearch:
image: elasticsearch-my_6_5_4
container_name: elasticsearch
environment:
- node.name=es01
- cluster.name=docker-cluster
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- esdata1:/usr/share/elasticsearch/data
ports:
- 9200:9200
- 9300:9300
networks:
- esnet
elasticsearch2:
image: elasticsearch-my_6_5_4
container_name: elasticsearch2
environment:
- node.name=es02
- cluster.name=docker-cluster
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
- discovery.type=zen
- "discovery.zen.ping.unicast.hosts=elasticsearch"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- esdata2:/usr/share/elasticsearch/data
networks:
- esnet
volumes:
esdata1:
driver: local
esdata2:
driver: local
networks:
esnet:
실행
$> docker-compose up -d
실행확인
$> docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b9ce987bdc8e elasticsearch-my_6_5_4 "/usr/local/bin/dock…" 36 seconds ago Up 34 seconds 0.0.0.0:9200->9200/tcp, 0.0.0.0:9300->9300/tcp elasticsearch
92f8e1d8853e elasticsearch-my_6_5_4 "/usr/local/bin/dock…" 36 seconds ago Up 34 seconds 9200/tcp, 9300/tcp elasticsearch2
http://127.0.0.1:9200/_cat/health
설치는 여기까지. 이제 Spring boot 를 이용하여 Document의 입력,수정,삭제,검색을 진행해 보자.