[투니월드] Springboot, Dockerfile로 이미지 생성, 빌드하기

두두·2023년 8월 22일
0

투니월드

목록 보기
2/2

Dockerfile 생성

FROM openjdk:11
CMD ["./mvnw", "clean", "package"]
ARG JAR_FILE=build/libs/*.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java", "-jar", "app.jar"]

gradle 빌드

./gradlew build -x test 

-x test: 테스트 실행 X


Docker Image Build

docker build --build-arg DEPENDENCY=build/dependency -t kang1221/toonidot --platform linux/amd64 .
  • 빌드 중에 Docker 이미지 내에서 사용할 빌드 인자를 정의합니다. 이 경우 DEPENDENCY라는 빌드 인자를 build/dependency 값으로 설정
  • -t 이미지 태그
  • --platform linux/amd64 . mac apple chip

도커환경으로 스프링부트 실행시키기

docker run --platform linux/amd64 kang1221/toonidot

🎯 오류 1
WARN 1 --- [ main] com.amazonaws.util.EC2MetadataUtils : Unable to retrieve the requested metadata (/latest/meta-data/instance-id). Failed to connect to service endpoint:

com.amazonaws.SdkClientException: Failed to connect to service endpoint:

🎯오류 2
2023-08-22 17:05:57.549 WARN 1 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 's3Config': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'cloud.aws.credentials.access-key' in value "${cloud.aws.credentials.access-key}"

🎯오류 3
Error creating bean with name 's3Config': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'cloud.aws.credentials.access-key' in value "${cloud.aws.credentials.access-key}"

docker push

docker push kang1221/toonidot

EC2 배포

도커 설치
$ sudo yum install docker
도커 실행
$ sudo systemctl start docker
도커 허브에 존재하는 이미지 파일 pull
$ sudo docker pull kang1221/toonidot
도커 이미지를 통해 스프링 부트 애플리케이션 배포
$ sudo docker run -p 8080:8080 kang1221/toonidot
// 포트 이해하기



Reference

https://zzang9ha.tistory.com/360
https://da2uns2.tistory.com/entry/Docker-도커에-Spring-Boot-구축하기

profile
멋쟁이가 될테야

0개의 댓글