Docker Java program mirroring

Docker Java program mirroring


Production steps

# 创建镜像制作目录
mkdir docker
cd docker

# 将oracle的jre包和生成好的程序jar放到目录中
# 为了制造较小体积的镜像,不使用jdk包,也没有必要使用它
cp .../jre-8u221-linux-x64.tar.gz ./
cp .../seckill-1.0-SNAPSHOT.jar ./

# 创建并编辑编辑Dockfile镜像生成文件
vim Dockerfile

# 将下面的内容写入文件中,详细的东西在后面会有说明
FROM docker.io/jeanblanchard/alpine-glibc
ADD jre-8u221-linux-x64.tar.gz /usr/java/jdk
ENV JAVA_HOME /usr/java/jdk/jre1.8.0_221
ENV PATH ${PATH}:${JAVA_HOME}/bin
COPY seckill-1.0-SNAPSHOT.jar /home/seckill-1.0-SNAPSHOT.jar
CMD java -jar /home/seckill-1.0-SNAPSHOT.jar

# 生成名称为seckill,版本为v0的镜像
docker build -t seckill:v0 .
# 运行镜像,我的Java程序是监听在8080端口的,所以将镜像容器的8080端口映射到宿主机的8080,并命名容器的名称为seckill
docker run --name seckill -p 8080:8080 seckill
# 查看当前seckill容器的输出,这里会打印显示Java的控制台输出内容
docker logs seckill

    Here to explain the contents Dockfile file:

  • FROM docker.io/jeanblanchard/alpine-glibc:docker of linux mirror There are many, such as Ubuntu, centos and the like, but their volume was relatively large, is simply a mirror of more than 400M, of which only a mirror of alpine less than 10M, very compact, so here it is chosen as the basis for the construction of a mirror. But alpine is based MUSL libs (mini libc), and Java-based GUN Standard C (glibc) library, and if no treatment, then Java will not run on it, but the Internet has already made big brother of glibc installed alpine mirror, we can directly use
  • ADD jre-8u221-linux-x64.tar.gz / usr / java / jdk: jre decompressed and compressed to add / usr / java / jdk directory
  • ENV JAVA_HOME /usr/java/jdk/jre1.8.0_221,ENV PATH $ {PATH}: $ {JAVA_HOME} / bin: This Java environment variables, where a stepped pit, to be noted that JAVA_HOME path setting, if your version of jre package and I are not the same, then, need to be modified, unzip my post here is jre1.8.0_221
  • COPY seckill-1.0-SNAPSHOT.jar /home/seckill-1.0-SNAPSHOT.jar: Copy add Java to the specified directory
  • CMD java -jar /home/seckill-1.0-SNAPSHOT.jar: Set to start the Java program to run after the container

    If docker not quite understand, you can see below me the process of making reference links

Reference links

Guess you like

Origin www.cnblogs.com/freedom-only/p/11294103.html