daangn-daangn / daangn-server

🥕당근 서버 리포지토리🥕
4 stars 2 forks source link

docker-compose 환경 내 kafka와 sync를 위한 DOCKERIZE 적용 #71

Closed cotchan closed 2 years ago

cotchan commented 2 years ago

이슈

cotchan commented 2 years ago

해결

원인

해결방법: DOCKERIZE

사용방법

ENV DOCKERIZE_VERSION v0.6.1
RUN wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
    && tar -C /usr/local/bin -xzvf dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
    && rm dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz
#!/bin/bash

echo "wait kafka server"
dockerize -wait tcp://kafka:9095 -timeout 20s

적용예시

FROM openjdk:11 as builder

COPY ./ ./

RUN chmod +x ./gradlew

RUN ./gradlew clean :chat-server:build -x test

FROM openjdk:11

ENV DOCKERIZE_VERSION v0.6.1
RUN wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
    && tar -C /usr/local/bin -xzvf dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
    && rm dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz

WORKDIR /app

COPY --from=builder chat-server/build/libs/*.jar ./chat-server.jar
COPY chat-server/docker-entrypoint.sh ./docker-entrypoint.sh

RUN chmod +x ./docker-entrypoint.sh
ENTRYPOINT ./docker-entrypoint.sh
#!/bin/bash

echo "wait kafka server"
dockerize -wait tcp://kafka:9095 -timeout 20s

echo "start chat-server"
java -jar ./chat-server.jar

실행결과

chat   | wait kafka server
chat   | 2022/06/19 01:39:31 Waiting for: tcp://kafka:9095
chat   | 2022/06/19 01:39:31 Problem with dial: dial tcp 172.18.0.4:9095: connect: connection refused. Sleeping 1s