// build.gradle
jar {
enabled = false
}
gradle 버전
# Stage 1: Build the application using Gradle with JDK 17
FROM openjdk:17-jdk-slim as builder
WORKDIR /build
# Copy Gradle build files
COPY build.gradle settings.gradle /build/
# Download dependencies without running tests
RUN ./gradlew build -x test --parallel --continue || true
# Copy the rest of the application code
COPY . /build
# Copy the .env file
COPY .env /build/.env
# Build the application without running tests
RUN ./gradlew build -x test --parallel
# Stage 2: Run the application using Amazon Corretto JDK 17
FROM amazoncorretto:17
WORKDIR /app
# Copy the built JAR file from the builder stage
COPY --from=builder /build/build/libs/*.jar mjuLetter.jar
# Copy the .env file from the builder stage
COPY --from=builder /build/.env .env
# Expose port 8080 to the outside world
EXPOSE 8080
# Run the JAR file with Java
ENTRYPOINT ["java", "-jar", "mjuLetter.jar"]
maven
FROM openjdk:17-jdk-slim as builder
WORKDIR /build
COPY pom.xml /build/
COPY src /build/src
RUN ./mvnw dependency:go-offline -B
COPY . /build
RUN ./mvnw clean package -DskipTests
FROM amazoncorretto:17
WORKDIR /app
COPY --from=builder /build/target/*.jar mjuLetter.jar
COPY --from=builder /build/.env .env
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "mjuLetter.jar"]
./gradlew clean build -x test
doker login -u [username]
# 기본 커맨드
# docker build -t [dockerHub ID]/[이미지명]:[태그명] [DockerFile위치]
# 태그 지정X 시 :latest 지정됨
$docker build -t [dockerHub ID]/[이미지명] .
docker images
# Docker Hub Push
docker push [DockerHub ID]/[image 파일명]
# Docker Pull + 컨테이너화(실행)
# 커맨드 기본 골조
docker run -d -p [로컬 port]:[도커 port] [dockerHub ID]/[이미지명]
# Docker 실행중인 컨터이너 확인
docker ps
# Docker 정지된 컨테이너 확인(실행중인것도 출력)
docker ps -a