java打包成docker images

4 篇文章 0 订阅

一个最简单的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

执行命令行

  1. 当前根目录
docker build -t teler/app:1.0.1 .
  • -t指images名称
  • .指路径
  1. 指定目录
    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,直接打包进去了

  • 如果使用目录文件以外的文件,需要设置运行目录为 … ,不再是 . ,这样才能找到文件

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值