특정 이미지를 기반으로 하여 새로운 이미지를 만들 수 있는 Docker build
에 대해 공부와 함께 이전에 ubuntu 14.04 위에 서비스로 elasticsearch 를 설치했던 내용들을 정리하기 위해 Dockerfile
을 만듬.
해당 elasticsearch는 x-pack을 사용하여, 인증받지 않은 임의의 유저는 특정 클러스터에 read 만 할 수 있도록 함.
아래 Dockerfile
, elasticsearch.yml
, roles.yml
를 한 폴더에 놓은 뒤, $ docker build
실행.
FROM mcpayment/ubuntu1404-java8 | |
MAINTAINER mail@jungbin.kim | |
# repository index 업데이트 | |
RUN apt-get -y -qq update | |
RUN wget -qO – https://artifacts.elastic.co/GPG-KEY-elasticsearch | apt-key add – | |
# Installing from the APT repository | |
RUN apt-get -y -qq install apt-transport-https | |
RUN echo “deb https://artifacts.elastic.co/packages/5.x/apt stable main” | tee -a /etc/apt/sources.list.d/elastic-5.x.list | |
RUN apt-get -y -qq update && \ | |
apt-get -y -qq install elasticsearch | |
# Install x-pack & Set super user(as admin) | |
WORKDIR /usr/share/elasticsearch | |
RUN bin/elasticsearch-plugin install x-pack –batch && \ | |
bin/x-pack/users useradd admin_user -p testPassword -r superuser | |
# config 파일 소스 | |
COPY elasticsearch.yml /etc/elasticsearch/ | |
COPY roles.yml /etc/elasticsearch/x-pack/ | |
# 나중에 내부 테스트를 위함 | |
# curl 설치 | |
RUN apt-get -y -qq install curl | |
# vi option 추가 | |
RUN echo “set autoindent \nset number \nset bs=2 \nset nocp” >> ~/.exrc | |
# 도커 컨테이너가 실행되었을 때 요청을 기다리고 있는(Listen) 포트를 지정 | |
EXPOSE 9200 | |
# 도커 컨테이너가 실행되었을 때 실행되는 명령어를 정의 | |
CMD service elasticsearch start && bash |
# Set the bind address to a specific IP (IPv4 or IPv6): | |
# 192.168.1.10 과 같은 ip에 접근하기 위함 | |
network.host: 0.0.0.0 | |
# create an anoynomous user to allow interaction without auth | |
xpack.security.authc: | |
# 임의의 유저(유저 이름 anonymous)에 viewer라는 role을 줌. | |
# (x-pack/roles.yml에서 viewer는 read만 가능하게 설정) | |
# https://www.elastic.co/guide/en/elasticsearch/reference/5.6/security-settings.html#anonymous-access-settings | |
anonymous: | |
username: anonymous | |
roles: viewer | |
# Disable default user ‘elastic’ | |
# https://www.elastic.co/guide/en/elasticsearch/reference/5.6/security-settings.html#password-security-settings | |
accept_default_password: false |
# The default roles file is empty as the preferred method of defining roles is | |
# through the API/UI. File based roles are useful in error scenarios when the | |
# API based roles may not be available. | |
viewer: | |
run_as: [ ‘anonymous’ ] # 적용될 유저 이름 여기서는 인증 받지 않은 임의의 유저 | |
cluster: [ “monitor” ] # 적용될 cluster들 | |
indices: | |
– names: [ ‘*’ ] # 허용 index를 패턴을 포함하여 정의 한다. | |
privileges: [ ‘read’ ] # 권한은 read만 부여한다. | |
query: ‘{“match_all”: {}}‘ # 권한으로 열어줄 문서 목록을 쿼리로 정의한다. |
위와 같이 dockerfile
을 별도로 만들지 않아도, Docker hub에 5.6 버전까지 docker 이미지가 있으며, 최신 버전(현재 6.3)의 elasticsearch docker image는 공식 제공 페이지에 존재.
사용한 docker file 명령어Permalink
RUN
: 쉘 명령어를 수행WORKDIR
: 현재 가리키고 있는 폴더 위치 변경COPY
: 특정 파일이나 폴더 docker image에 복사EXPOSE
: docker container 내의 portCMD
: docker image를 container로 실행할 때 실행되는 명령어 지정
Error HandlingPermalink
apt-get install apt-transport-https
명령어를 실행할 때, Unable to locate package apt-transport-https
에러 발생Permalink
이 글을 참고하여, /etc/apt/sources.list.d/
경로에 elastic 관련 .list 파일을 삭제하고, 다시 install 명령어 실행.