一个最简单的jar包的Dockerfile制作
openjdk的dockerhub地址
在代码根目录创建Dockerfile文件,内容如下
FROM openjdk:8-alpine
LABEL "Author"="Teler" \
"email"="terler96@qq.com" \
version=0.0.1 \
description="jar运行在docker中的示例系统"
COPY target/app.jar /home/app/app.jar
WORKDIR /home/app
ENTRYPOINT ["java","-jar","app.jar"]
EXPOSE 8080
执行命令行
- 当前根目录
docker build -t teler/app:1.0.1 .
- -t指images名称
- .指路径
- 指定目录
docker build -f <path>/Dockerfile -t <name>:<version> .
说明&注意点
- 我为了缩小体积使用的alpine版本,官方建议如下
This image is based on the popular Alpine Linux project, available in the alpine official image. Alpine Linux is much smaller than most distribution base images (~5MB), and thus leads to much slimmer images in general.
The OpenJDK port for Alpine is not in a supported release by OpenJDK, since it is not in the mainline code base. It is only available as early access builds of OpenJDK Project Portola. See also this comment. So this image follows what is available from the OpenJDK project’s maintainers.
What this means is that Alpine based images are only released for early access release versions of OpenJDK. Once a particular release becomes a “General-Availability” release, the Alpine version is dropped from the “Supported Tags”; they are still available to pull, but will no longer be updated.
-
no main manifest attribute, in app.jar
没有主属性清单:忘了package,直接打包进去了 -
如果使用目录文件以外的文件,需要设置运行目录为 … ,不再是 . ,这样才能找到文件

本文详细指导如何使用Dockerfile创建一个基于openjdk:8-alpine的jar包应用镜像,包括Dockerfile编写、标签设置、体积优化和注意事项,适合初学者理解Alpine的使用和Java应用部署。
6031

被折叠的 条评论
为什么被折叠?



