docker构建耗时太长

oxcyiej7  于 2021-07-13  发布在  Java
关注(0)|答案(0)|浏览(255)

下面是我们用来构建spring启动应用程序的dockerfile示例。这个构建大约需要600-700秒。这只是一个应用程序,我们还有大约40个微服务应用程序。如何缩短构建时间。


#### Stage 1: Build the application

FROM adoptopenjdk/openjdk11:jdk-11.0.10_9-alpine as build

# Set the current working directory inside the image

WORKDIR /app

# Copy maven executable to the image

COPY mvnw .
COPY .mvn .mvn

# Copy the pom.xml file

COPY pom.xml .

# Build all the dependencies in preparation to go offline.

# This is a separate step so the dependencies will be cached unless

# the pom.xml file has changed.

RUN ./mvnw dependency:go-offline -B

# Copy the project source

COPY src src

# Package the application

RUN ./mvnw package -DskipTests
RUN mkdir -p target/dependency && (cd target/dependency; jar -xf ../*.jar)

#### Stage 2: A minimal docker image with command to run the app

FROM adoptopenjdk/openjdk11:jre-11.0.10_9-alpine

ARG DEPENDENCY=/app/target/dependency

# Copy project dependencies from the build stage

COPY --from=build ${DEPENDENCY}/BOOT-INF/lib /app/lib
COPY --from=build ${DEPENDENCY}/META-INF /app/META-INF
COPY --from=build ${DEPENDENCY}/BOOT-INF/classes /app

ENTRYPOINT ["java","-cp","app:app/lib/*","com.app.AppServiceApplication"]```

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题