最後更新日期: 2024 年 1 月 28 日
方法一
# /unicorn-store-spring/Dockerfile
FROM public.ecr.aws/docker/library/maven:3.9-amazoncorretto-17-al2023 as builder
COPY ./pom.xml ./pom.xml
RUN mvn dependency:go-offline -f ./pom.xml
COPY src ./src/
RUN mvn clean package && mv target/store-spring-1.0.0-exec.jar store-spring.jar
RUN rm -rf ~/.m2/repository
FROM public.ecr.aws/docker/library/amazoncorretto:17.0.9-al2023
RUN yum install -y shadow-utils
COPY --from=builder store-spring.jar store-spring.jar
RUN groupadd --system spring -g 1000
RUN adduser spring -u 1000 -g 1000
USER 1000:1000
EXPOSE 8080
ENTRYPOINT ["java","-jar","-Dserver.port=8080","/store-spring.jar"]
方法二
FROM public.ecr.aws/docker/library/maven:3.9-amazoncorretto-17-al2023 as builder
RUN yum install -y shadow-utils
COPY store-spring.jar store-spring.jar
RUN groupadd --system spring -g 1000
RUN adduser spring -u 1000 -g 1000
USER 1000:1000
EXPOSE 8080
ENTRYPOINT ["java","-jar","-Dserver.port=8080","/store-spring.jar"]
方法三
FROM public.ecr.aws/docker/library/maven:3.9-amazoncorretto-17-al2023 as builder
RUN yum install -y shadow-utils
COPY ./pom.xml ./pom.xml
RUN mvn dependency:go-offline -f ./pom.xml
COPY src ./src/
RUN mvn clean package && mv target/store-spring-1.0.0-exec.jar store-spring.jar
RUN rm -rf ~/.m2/repository
RUN groupadd --system spring -g 1000
RUN adduser spring -u 1000 -g 1000
USER 1000:1000
EXPOSE 8080
ENTRYPOINT ["java","-jar","-Dserver.port=8080","/store-spring.jar"]