小伙伴们好呀,今天来和大家聊聊这个 Springboot 在为创建高效容器方面中做的一个改动 。
当然,写这篇文章也不是因为实际项目真的需要我去研究这东西,而是我在上篇文章
《为什么SpringBoot可以直接运行 jar 包?》 中留了坑 ,还有错误得纠正:pig2: (原文也稍微改了下,但是只能改20字 )
这里应该改为
用 jarmode 的 extract 参数会自动将 jar 包中的文件按 layers.idx 中的分层提取出来。

There’s always a certain amount of overhead when running a fat jar without unpacking it, and in a containerized environment this can be noticeable. The other issue is that putting your application’s code and all its dependencies in one layer in the Docker image is sub-optimal.
上面这两句摘自 Springboot2.4.13 官方文档,但是这个改动是 2.3 就有了的(看了下 2.3 的,也还是这几句话:pig:)
https://docs.spring.io/spring-boot/docs/2.4.13/reference/html/spring-boot-features.html#boot-features-container-images
大意就是说,
在容器中,如果没有解压就直接运行一个 jar 包,它带来的开销是明显的
将 应用代码和包依赖都混在同一层,也是可以被优化的地方。
w(゚Д゚)w ,感觉说的很有道理 哈哈哈