docker打jdk 1.8镜像
基础镜像拉取此处演示采用网易云提供的centos基础镜像作为演示model。将已有的jdk包打到docker镜像中。此处演示jdk版本jdk-8u201-linux-x64.tar.gz拉取镜像docker pull hub.c.163.com/public/centos:7.2-tools查看镜像docker images结果G:\dockertest\jdk>docke...
·
基础镜像拉取
此处演示采用网易云提供的centos基础镜像作为演示model。将已有的jdk包打到docker镜像中。此处演示jdk版本jdk-8u201-linux-x64.tar.gz
拉取镜像
docker pull hub.c.163.com/public/centos:7.2-tools
查看镜像
docker images
结果
G:\dockertest\jdk>docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hub.c.163.com/public/centos 7.2-tools 4a4618db62b9 3 years ago 515MB
通过docker tag命令将下载的CentOS镜像名称换成centos;并删除老标签的镜像文件(可选)。
docker tag hub.c.163.com/public/centos/7.2-tools centos-7.2
docker rmi hub.c.163.com/public/centos/7.2-tools 可选
编写dockerfile
Dockerfile
# CentOS with JDK 8
# Author xxxx
# build a new image with basic centos
FROM centos-7.2
# make a new directory to store the jdk files
RUN mkdir /usr/local/java
# copy the jdk archive to the image,and it will automaticlly unzip the tar file
ADD jdk-8u201-linux-x64.tar.gz /usr/local/java/
# make a symbol link
RUN ln -s /usr/local/java/jdk1.8.0_201 /usr/local/java/jdk
# set environment variables
ENV JAVA_HOME /usr/local/java/jdk
ENV JRE_HOME ${JAVA_HOME}/jre
ENV CLASSPATH .:${JAVA_HOME}/lib:${JRE_HOME}/lib
ENV PATH ${JAVA_HOME}/bin:$PATH
执行build命令
docker build -t="centos-7.2" .
日志
G:\dockertest\jdk>docker build -t="centos-7.2" .
Sending build context to Docker daemon 191.8MB
Step 1/8 : FROM centos-7.2
---> 4a4618db62b9
Step 2/8 : RUN mkdir /usr/local/java
---> Running in 21cb3d686cc6
Removing intermediate container 21cb3d686cc6
---> e0bf568d50ab
Step 3/8 : ADD jdk-8u201-linux-x64.tar.gz /usr/local/java/
---> 27c4b998563c
Step 4/8 : RUN ln -s /usr/local/java/jdk1.8.0_201 /usr/local/java/jdk
---> Running in 94a86d36eabc
Removing intermediate container 94a86d36eabc
---> f5f331af1392
Step 5/8 : ENV JAVA_HOME /usr/local/java/jdk
---> Running in 8b42ed9454f5
Removing intermediate container 8b42ed9454f5
---> 44fcea710c55
Step 6/8 : ENV JRE_HOME ${JAVA_HOME}/jre
---> Running in 6a1a8c794183
Removing intermediate container 6a1a8c794183
---> b17a8fefc755
Step 7/8 : ENV CLASSPATH .:${JAVA_HOME}/lib:${JRE_HOME}/lib
---> Running in 79b7719361ab
Removing intermediate container 79b7719361ab
---> 400072b486c4
Step 8/8 : ENV PATH ${JAVA_HOME}/bin:$PATH
---> Running in eceb2c5dcf0a
Removing intermediate container eceb2c5dcf0a
---> 296c05b8e7f8
Successfully built 296c05b8e7f8
Successfully tagged centos-7.2:latest
SECURITY WARNING: You are building a Docker image from Windows against a non-Windows Docker host. All files and directories added to build context will have '-rwxr-xr-x' permissions. It is recommended to double check and reset permissions for sensitive files and directories.
启动容器测试
>docker run -t -i centos-7.2:latest /bin/bash
执行 java -version
打包成功
[root@4b62de997da2 /]# java -version
java version "1.8.0_201"
Java(TM) SE Runtime Environment (build 1.8.0_201-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.201-b09, mixed mode)
更多推荐
已为社区贡献2条内容
所有评论(0)