Sample RestAPI, Git Action CI
$ curl localhost:8080/health -i
HTTP/1.1 200
Content-Type: text/plain;charset=UTF-8
Content-Length: 17
Date: Mon, 09 Sep 2024 03:33:43 GMT
Server is running
# Stage 1: Build the application using Maven
FROM maven:3.8.4-openjdk-17 AS build
WORKDIR /app
COPY pom.xml .
RUN mvn dependency:go-offline
COPY src ./src
RUN mvn clean package -DskipTests
# Stage 2: Run the application using OpenJDK
#FROM openjdk:17-jdk-slim
FROM openjdk:17-jdk
WORKDIR /app
COPY --from=build /app/target/*.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "app.jar"]
# Docker 빌드 명령
$ docker build -t edu00/samplejava:v1.4 .
# Docker 컨테이너 실행
$ docker run -p 8080:8080 du00/samplejava:v1.4
# test
# 다른 터미널에서...
$ curl localhost:8080/health -i
이제 http://localhost:8080/health에서 Spring Boot 애플리케이션을 확인
Docker에서 buildx 명령을 사용하여 이미지를 빌드하고 푸시할 때, 기본적으로 빌드된 이미지는 로컬에 저장되지 않는다. 로컬에 이미지를 생성하려면 --load 또는 --output 옵션을 사용해야 한다.
# push만 사용
docker buildx build \
--cache-from=type=registry,ref=sdu00/samplejava:cache \
--cache-to=type=registry,ref=du00/samplejava:cache,mode=max \
--push \
-t du00/samplejava:v1.4 .
# push, load 모두 사용
docker buildx build \
--cache-from=type=registry,ref=edu00/samplejava:cache \
--cache-to=type=registry,ref=edu00/samplejava:cache,mode=max \
--push \
--load \
-t edu00/samplejava:v1.1 .
# push 없이 load 만 : registry 에 push 는 안된다.
docker buildx build \
--cache-from=type=registry,ref=edu00/samplejava:cache \
--cache-to=type=registry,ref=edu00/samplejava:cache,mode=max \
--load \
-t edu00/samplejava:v1.3 .
- --load 옵션은 멀티 플랫폼 빌드를 지원하지 않는다. 단일 플랫폼(--platform linux/amd64)에서만 작동한다.
# Docker 컨테이너 실행
$ docker run -p 8080:8080 edu00/samplejava
# test
# 다른 터미널에서...
$ curl localhost:8080/health -i