-
(kotlin)gradle spring boot application dockerizeSpring 2023. 9. 28. 19:07
https://spring.io/guides/topicals/spring-boot-docker/
Getting Started | Spring Boot Docker
The Spring Boot Maven and Gradle plugins use buildpacks in exactly the same way that the pack CLI does in the following examples. The resulting images are identical, given the same inputs. Cloud Foundry has used containers internally for many years now, an
spring.io
1. spring boot application initialize
https://start.spring.io/ 에서 생성했다
앱 특성에 따라 아무거나 골라도 상관 없지만 kotlin+gradle 설정이 필요하다.
2. Dockerfile 작성
FROM eclipse-temurin:17-jdk VOLUME /tmp ARG JAR_FILE COPY ${JAR_FILE} app.jar ENTRYPOINT ["java","-jar","/app.jar"]
간단한 도커파일을 작성했다.
앱이 무거워져서 이미지 빌드 시간이 길어질 경우 layered jar를 활용한 멀티 스테이지 빌드로 시간 단축이 가능하다.
3. docker build
4. 실행
이 방식이 있고, palantir라는 라이브러리를 사용해서 gradle task로 추가해 사용하는 방법이 있다.
https://plugins.gradle.org/plugin/com.palantir.docker
Gradle - Plugin: com.palantir.docker
Version 0.35.0 (latest) Created 03 April 2023. Gradle Docker is a simple docker orchestrator for executing docker build and push from within Gradle. plugins { id("com.palantir.docker") version "0.35.0" } buildscript { repositories { maven { url = uri("http
plugins.gradle.org
또, spring boot 프로젝트라면 2.3 이후 버전부터는 maven, gradle 빌드팩 지원이 포함되어 있다.
https://spring.io/blog/2020/01/27/creating-docker-images-with-spring-boot-2-3-0-m1
Creating Docker images with Spring Boot 2.3.0.M1
Spring Boot 2.3.0.M1 has just been released and it brings with it some interesting new features that can help you package up your Spring Boot application into Docker images. In this blog post we’ll take a look at the typical ways developers create Docker
spring.io
별다른 설정 없이 bootBuildImage gradle task를 실행하면 이미지가 빌드되고, 위와 똑같이 실행된다.
빌드 파이프라이닝이 복잡하지 않은 초기 애플리케이션이라면 이렇게 구성해도 괜찮을 것 같다.
'Spring' 카테고리의 다른 글
STOMP와 WebSocket으로 아주 간단한 메시징 시스템 만들기 (422) 2021.10.19 Spring Dependency Injection의 종류 - Constructor, Setter, Field (401) 2021.10.16 Spring에서는 DI를 통해 IoC를 구현한다 (416) 2021.10.16 Spring AOP(Aspect-Oriented Programming)의 이해 (407) 2021.10.03 @(Annotation)을 이용한 Spring Container Configuration (449) 2021.10.02