我有一个SpringBoot项目,我部署到了Google App Engine上。它工作得很好。该网站的访问量不是很高。但它的账单成本却在上升。
因此,我决定将我的SpringBoot项目转移到"Cloud Run“。
我已尝试使用以下链接https://cloud.google.com/run/docs/quickstarts/build-and-deploy/java
但在上面的教程中,他们详细介绍了jar文件。
本项目中使用的是Jave 8,SpringBoot 2.3.0版本。
应用程序引擎的pom.xml
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>appengine-maven-plugin</artifactId>
<version>2.2.0</version>
<configuration>
<projectId>MY-SPRING-BOOT-APP</projectId>
<version>1</version>
<ssl-enabled>true</ssl-enabled>
</configuration>
</plugin>DockerFile
# Use the official maven/Java 8 image to create a build artifact.
# https://hub.docker.com/_/maven
FROM maven:3.8-jdk-11 as builder
# Copy local code to the container image.
WORKDIR /app
COPY pom.xml .
COPY src ./src
# Build a release artifact.
RUN mvn package -DskipTests
# Use AdoptOpenJDK for base image.
# It's important to use OpenJDK 8u191 or above that has container support enabled.
# https://hub.docker.com/r/adoptopenjdk/openjdk8
# https://docs.docker.com/develop/develop-images/multistage-build/#use-multi-stage-builds
FROM adoptopenjdk/openjdk11:alpine-slim
# Copy the jar to the production image from the builder stage.
COPY --from=builder /app/target/myapp.war /target/myapp.war
# Run the web service on container startup.
CMD ["java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "/target/myapp.war"]
#CMD ["catalina.sh","run"]有什么想法吗?
发布于 2021-06-12 18:21:10
最后,我成功地将我的springboot应用程序部署到cloud run,而无需更改包类型。
# Use the official maven/Java 8 image to create a build artifact.
# https://hub.docker.com/_/maven
FROM maven:3.8-jdk-11 as builder
# Copy local code to the container image.
WORKDIR /app
COPY pom.xml .
COPY src ./src
# Build a release artifact.
RUN mvn package -DskipTests
# Use AdoptOpenJDK for base image.
# It's important to use OpenJDK 8u191 or above that has container support enabled.
# https://hub.docker.com/r/adoptopenjdk/openjdk8
# https://docs.docker.com/develop/develop-images/multistage-build/#use-multi-stage-builds
FROM adoptopenjdk/openjdk11:alpine-slim
# Copy the jar to the production image from the builder stage.
COPY --from=builder /app/target/myapp-*.war /myapp.war
# Run the web service on container startup.
CMD ["java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "/myapp.war"]https://stackoverflow.com/questions/67749856
复制相似问题