欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

使用Docker构建jdk1.8镜像

程序员文章站 2024-03-13 16:09:15
...

一、下载centos镜像

下载自己需要的版本TAG,详见:

#docker pull centos:centos7

二、下载jdk1.8,并上传到/usr/local/src目录,然后解压

#cd /usr/local/src
#tar -zxvf jdk-8u201-linux-x64.tar.gz
#ls
jdk1.8.0_201  jdk-8u201-linux-x64.tar.gz

三、创建Dockerfile

先在/usr/local目录下创建jdk目录,并将/usr/local/src下的jdk-8u201-linux-x64.tar.gz复制到/usr/local/jdk目录下,然后创建Dockerfile文件

#mkdir /usr/local/jdk
#cd /usr/local/jdk
#vi Dockerfile

FROM centos:centos7
MAINTAINER tom
RUN mkdir /usr/local/jdk
WORKDIR /usr/local/jdk
ADD jdk-8u201-linux-x64.tar.gz /usr/local/jdk

ENV JAVA_HOME /usr/local/jdk/jdk1.8.0_201
ENV JRE_HOME /usr/local/jdk/jdk1.8.0_201/jre
ENV PATH $JAVA_HOME/bin:$PATH

 

四、使用Dockerfile构建jdk1.8镜像

#docker build -t jdk1.8 .
Sending build context to Docker daemon  191.8MB
Step 1/8 : FROM centos:centos7
 ---> 9f38484d220f
Step 2/8 : MAINTAINER tom
 ---> Running in 9ebabac7e9e0
Removing intermediate container 9ebabac7e9e0
 ---> 6e65e30640c0
Step 3/8 : RUN mkdir /usr/local/jdk
 ---> Running in 5805a4f50285
Removing intermediate container 5805a4f50285
 ---> 8ebaedf8bd72
Step 4/8 : WORKDIR /usr/local/jdk
 ---> Running in c68e7f94ce6d
Removing intermediate container c68e7f94ce6d
 ---> f4df19bf9468
Step 5/8 : ADD jdk-8u201-linux-x64.tar.gz /usr/local/jdk
 ---> 1fa5d55acc2e
Step 6/8 : ENV JAVA_HOME /usr/local/jdk/jdk1.8.0_201
 ---> Running in c9c93a299d59
Removing intermediate container c9c93a299d59
 ---> 09b5bfd906dc
Step 7/8 : ENV JRE_HOME /usr/local/jdk/jdk1.8.0_201/jre
 ---> Running in d4509f0c2af8
Removing intermediate container d4509f0c2af8
 ---> 1d6b070b3985
Step 8/8 : ENV PATH $JAVA_HOME/bin:$PATH
 ---> Running in 190dde73be87
Removing intermediate container 190dde73be87
 ---> 50016b7aac0c
Successfully built 50016b7aac0c
Successfully tagged jdk1.8:latest

五、在镜像仓库中查看是否构建成功

#docker images
REPOSITORY                TAG                 IMAGE ID            CREATED             SIZE
jdk1.8                    latest              50016b7aac0c        10 seconds ago      598MB

六、启动jdk容器

#docker run -di --name=jdk1.8 jdk1.8
e04f670691cd301b28fb56c25b12eae4851f583fa7abac367164a0ee68ad7241

七、进入jdk容器,查看是否安装正确(即查看安装之后的目录)

#docker exec -it jdk1.8 /bin/bash
[[email protected] jdk]# pwd
/usr/local/jdk
[[email protected] jdk]# ls
jdk1.8.0_201