目录

java打包成docker-images

# 一个最简单的jar包的Dockerfile制作

# openjdk的dockerhub地址 (opens new window)


# 在代码根目录创建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
2
3
4
5
6
7
8
9
10
11
12
13

# 执行命令行

  1. 当前根目录
docker build -t teler/app:1.0.1 .
1
  • -t指images名称
  • .指路径
  1. 指定目录
    docker build -f <path>/Dockerfile -t <name>:<version> .
1

# 说明&注意点

  • 我为了缩小体积使用的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,直接打包进去了

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

上次更新: 2024-11-06, 19:27:10
最近更新
01
java playwright爬虫
11-06
02
连接chrome调试
07-23
03
连接chrome调试
07-23
更多文章>