簡體   English   中英

Docker Springboot Webapp 包含的庫

[英]Docker Springboot Webapp Included Libraries

我有一個 Springboot jar 通過 Docker 部署為 web 應用程序。 這是我的 Dockerfile 的基本輪廓。

#
# Build App
#
FROM maven:3.6.3-openjdk-15-slim AS build

# Copy Parent Project
COPY src /home/app/src
COPY pom.xml /home/app

RUN mvn -f /home/app/pom.xml clean package -DskipTests

#
# Deploy App
#
FROM openjdk:15-jdk-alpine
COPY --from=build /home/app/my-app/target/my-app-rest-0.0.1-SNAPSHOT.jar /usr/local/lib/app.jar
ENTRYPOINT exec java -Djava.security.egd=file:/dev/./urandom -jar /usr/local/lib/app.jar

我最初在互聯網上發現了與此 Dockerfile 類似的模式,我想我了解其中的大部分內容,但有一件事讓我無法理解:我的應用程序運行所需的所有依賴項app.jar到哪里? 我的項目正在運行和執行得很好,所以它們必須在我的容器中的某個地方。 但是我已經搜索和搜索但找不到任何依賴項 jars 甚至我的 webapp 的WEB-INF目錄。 我知道我的實際應用程序 jar 在/usr/local/lib/中,但這就是我能推斷的全部。

是否存在依賴項/webapp 配置會 go 的默認位置? 有什么可以添加到我的 Dockerfile 來定義 go 的位置嗎?

Spring 引導將所有依賴項(jar)放入胖可執行文件 jar 中,這是您傳遞到運行階段的那個,也是您使用 Z93F725A07423FE1C889F448B33D21F46 命令運行的那個。

由於 jar 文件只是壓縮檔案,因此您可以使用解壓縮並在其中窺視來提取它們:

docker cp <container-id>:/home/app/my-app/target/my-app-rest-0.0.1-SNAPSHOT.jar myjar.jar
unzip myjar.jar -d myjar
ls -al myjar/BOOT-INF/lib

你會得到所有 jars 你 spring 啟動應用程序依賴的列表。

更多信息在這里這里

Maven is used to build your .jar package, while you only need to put the .jar package into docker image and add java -jar... as the entry point.

請注意,Docker 強烈建議程序員將應用程序分成單獨的 docker 映像。 即使您可以同時擁有 Maven 和.jar ,也不要這樣做。

是否存在依賴項/webapp 配置會 go 的默認位置?

是的。 這是我在工作中使用的 Dockerfile。 您在開發機器上而不是在 Dockerfile 中運行 maven 命令,例如cleanpackage

FROM openjdk:8-jdk-alpine
# You want to change JDK version.

ADD target/*.jar app.jar
# You have to place this Dockerfile in the SAME directory with the target folder. Then this Dockerfile pulls whatever jar you have under target, renames it to app.jar and adds it to the build.

EXPOSE 9001
# You want to change this to whatever port your java app listens on.

ENTRYPOINT ["java", "-jar", "/app.jar"]
# Typical command you use to run .jar package but this time, you use it as the entrypoint.

一旦你有了.jar package, cd到 Dockerfile 目錄和docker build. .

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM