'docker-compose'에 해당되는 글 4건

  1. 2022.03.23 [Docker] Spring Boot App 도커 적용
  2. 2021.07.14 [Docker] 로컬에 MySQL 설치 합니다.
  3. 2021.02.01 [Docker] ARG 와 ENV 사용 예제.
  4. 2020.09.10 [Elasticsearch+Docker] 로컬 클러스터 구성 시 흔한 실수.

[Docker] Spring Boot App 도커 적용

ITWeb/개발일반 2022. 3. 23. 10:49

Springboot 로 WAS 생성 후 이를 도커 기반으로 생성, 실행 하기 위해서 관련 내용 기록 합니다.

 

관련 문서)

https://spring.io/guides/gs/spring-boot-docker/
https://docs.spring.io/spring-boot/docs/current/gradle-plugin/reference/htmlsingle/

 

과정)

1. 프로젝트를 빌드 해서 bootJar 를 생성 합니다.

보통 build/libs 에 생성이 됩니다.

 

2. Dockerfile 을 생성 합니다.

여기서 bootJar 를 ADD 해야 하는데 Dockerfile 과 같은 Depth 에 위치 하거나 하위에 위치해야 합니다.

상위에 bootJar 가 있을 경우 permission denied 에러가 발생 합니다.

 

3. Image 생성을 합니다.

$ docker build -t 이미지명:태그 .

태그 정보는 jenkins 에서 build number 를 부여 하거나 운영 규칙을 정해서 관리 합니다.

registry 를 운영하고 있으면 생성된 이미지를 등록 합니다.

 

4. docker-compose.yml 을 생성 합니다.

registry 를 운영하고 있으면 registry 에서 이미지를 받아 옵니다.

 

관련 예제 코드들은 위 문서에 잘 나와 있으니 참고 하면 됩니다.

 

아래는 그냥 참고용으로 올려 봅니다.

build.gradle)
...중략...
bootJar {
  destinationDirectory=file('docker/libs')
  enabled = true
}
...중략...

$ export TAG=1.0.0
$ docker build -t boot-app:$TAG .


Case 1) docker/Dockerfile
FROM openjdk:8-jdk-alpine
ARG JAR_FILE=./libs/*.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","/app.jar"]

Case 2) docker/Dockerfile
FROM openjdk:8-jdk-alpine
ARG JAR_FILE=./libs/*.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT java \
-jar app.jar

Case 3) docker/Dockerfile
ENV heapSize="-Xms2048 -Xmx2048m"
FROM openjdk:8-jdk-alpine
ARG JAR_FILE=./libs/*.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","${heapSize}","-jar","/app.jar"]

Case 4) docker/Dockerfile
FROM openjdk:8-jdk-alpine
ARG JAR_FILE=./libs/*.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT java \
${heapSize} \
-jar app.jar

ENTRYPOINT 추가 옵션)
-Djava.security.egd=file:/dev/./urandom \
-Dspring.profiles.active=local


docker-compose) docker/docker-compose.yml
version: '3.7'

services:
  boot-app:
    container_name: boot-app
    image: boot-app:${TAG}
    environment:
      - TZ=Asia/Seoul
      - env=local
      - "heapSize=-Xms2048m -Xmx2048m"
    ports:
      - "8080:8080"
    volumes:
      - ./logs:/home/appuser/logs
    sysctls:
      - net.core.somaxconn=65000
    restart: on-failure

 

:

[Docker] 로컬에 MySQL 설치 합니다.

Cloud&Container/IaC 2021. 7. 14. 19:39

요즘 잘 되어 있는 container 기반으로 구성 하면 되지 않겠습니까?

 

version: '3.7'

services:
  db:
    image: mysql
    container_name: local-mysql
    command: --default-authentication-plugin=mysql_native_password
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: local
      MYSQL_USER: henry
      MYSQL_PASSWORD: henry
      MYSQL_DATABASE: henry
    volumes:
      - ./data:/var/lib/mysql
    ports:
      - 3306:3306

  adminer:
    image: adminer
    restart: always
    ports:
      - 8888:8888

$ docker-compose up -d

이제 client tool 을 이용해서 접속해 보시면 됩니다. :)

:

[Docker] ARG 와 ENV 사용 예제.

Cloud&Container/IaC 2021. 2. 1. 14:55

 

https://docs.docker.com/engine/reference/builder/#arg
https://docs.docker.com/engine/reference/builder/#env
https://docs.docker.com/compose/reference/build/
https://docs.docker.com/compose/environment-variables/

 

docker build 시 --builg-arg 를 사용 할 때가 있는데요.

arg 와 env 에 대한 차이를 이해 하고 사용 하면 좋을 것 같아 기록해 봅니다.

 

제가 하고 싶었던 건 아래와 같습니다.

 

파일 구조)

ㄴ .env
ㄴ docker-compose.yml
ㄴ Dockerfile

$ docker build --build-arg BASTION_IP=xxx.xxx.xxx.xxx --tag ecos-installer-web:0.0.1 .

 

여기서 --build-arg 를 사용하지 않고 build 를 하고 싶었습니다.
그래서 .env 를 구성 하고
docker-compose 를 이용해서 build 를 하는 방식으로 변경을 했습니다.

 

.env 에 BASTION_IP 추가)

BASTION_IP=xxx.xxx.xxx.xxx

 

Dockerfile 에 ARG 추가)

ARG BASTION_IP
...중략...
ENV configTerraformAwsBastionIp $BASTION_IP

 

docker-compose.yml 에 build 추가)

build:
  context: .
    args:
      - BASTION_IP=${BASTION_IP}

 

이렇게 변경 하고 docker build 를 하지 않고 docker-compose build 로 처리 했습니다.

$ docker-compose build or docker-compose up

 

:

[Elasticsearch+Docker] 로컬 클러스터 구성 시 흔한 실수.

Elastic/Elasticsearch 2020. 9. 10. 08:54

Elasticsearch 가 각 노드들과 discovery 를 하기 위해서는 Transport 통신이 이루어져야 합니다.

문서에 정확하게 나와 있으나 놓치기 쉬운 부분이라 기록해 봅니다.

 

[참고문서]

https://www.elastic.co/guide/en/elasticsearch/reference/current/discovery-settings.html
https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-discovery-bootstrap-cluster.html
https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-discovery-settings.html

 

[Content Snippet]

[discovery.seed_hosts]

Provides a list of the addresses of the master-eligible nodes in the cluster.

1. transport.profiles.default.port
2. transport.port
If neither of these is set then the default port is 9300.

[Example Configuration]

[Node 1 - docker-compose.yml]
version: '3.7'

services:
  docker-es:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.9.1
    container_name: e1
    environment:
      - cluster.name=e3k1
      - node.name=e1
...중략...
      - discovery.seed_hosts=host.docker.internal:9300,host.docker.internal:9301,host.docker.internal:9302
      - cluster.initial_master_nodes=e1,e2,e3
...중략...

[Node 2 - docker-compose.yml]
version: '3.7'

services:
  docker-es:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.9.1
    container_name: e2
    environment:
      - cluster.name=e3k1
      - node.name=e2
...중략...
      - discovery.seed_hosts=host.docker.internal:9300,host.docker.internal:9301,host.docker.internal:9302
      - cluster.initial_master_nodes=e1,e2,e3
...중략...

[Node 3 - docker-compose.yml]
version: '3.7'

services:
  docker-es:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.9.1
    container_name: e3
    environment:
      - cluster.name=e3k1
      - node.name=e3
...중략...
      - discovery.seed_hosts=host.docker.internal:9300,host.docker.internal:9301,host.docker.internal:9302
      - cluster.initial_master_nodes=e1,e2,e3
...중략...

 

위에 작성된 설정 예제는 로컬에서 3개의 Elasticsearch 컨테이너를 실행 시켜서 클러스터링 시키는 예제 입니다.

이 방법 말고도 하나의 docker-compose.yml 에 구성을 하셔도 됩니다. (단, 설정이 조금 달라 집니다.)

 

주의 점은,

위에 언급된 내용처럼 Transport 통신을 한다는 것을 잊으면 안된다는 것입니다.

: