11 Dockerfile构建jdk1.8镜像

# 创建目录
[root@localhost gp6]# mkdir docker-jdk8]

# 切换目录,将jdk1.8.0_191.tar.gz上传到该目录
[root@localhost gp6]# cd docker-jdk8/

# 撰写Dockerfile文件(不能更换名称)
[root@localhost docker-jdk8]# vi Dockerfile
# 指定基础镜像
FROM centos:7

# 指定镜像的创建者
MAINTAINER gp6

# 设置工作目录
WORKDIR /usr

# 创建目录
RUN mkdir /usr/local/java

# 添加压缩包
ADD jdk1.8.0_191.tar.gz /usr/local/gp6/java

# 设置环境变量
ENV JAVA_HOME /usr/local/gp6/java/jdk1.8.0_191
ENV JRE_HOME $JAVA_HOME/jre
ENV PATH $JAVA_HOME/bin:$PATH

# 构建jdk1.8
[root@localhost docker-jdk8]#  docker build -t='jdk1.8' .
Sending build context to Docker daemon  189.9MB
Step 1/8 : FROM centos:7
 ---> 5e35e350aded
Step 2/8 : MAINTAINER gp6
 ---> Using cache
 ---> 51c6f6c8551e
Step 3/8 : WORKDIR /usr
 ---> Using cache
 ---> 9f41fe562ade
Step 4/8 : RUN mkdir /usr/local/java
 ---> Running in a80327e2aa39
Removing intermediate container a80327e2aa39
 ---> ac43fb286c89
Step 5/8 : ADD jdk1.8.0_191.tar.gz /usr/local/gp6/java
 ---> f45054f79760
Step 6/8 : ENV JAVA_HOME /usr/local/gp6/java/jdk1.8.0_191
 ---> Running in 0bd98a21e21e
Removing intermediate container 0bd98a21e21e
 ---> af9324e74ed8
Step 7/8 : ENV JRE_HOME $JAVA_HOME/jre
 ---> Running in 71e6ddff6aa0
Removing intermediate container 71e6ddff6aa0
 ---> 14eb2ab8dba5
Step 8/8 : ENV PATH $JAVA_HOME/bin:$PATH
 ---> Running in b575b39901af
Removing intermediate container b575b39901af
 ---> 83df82df73f0
Successfully built 83df82df73f0
Successfully tagged jdk1.8:latest

# 查看镜像列表
[root@localhost docker-jdk8]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED              SIZE
jdk1.8              latest              83df82df73f0        About a minute ago   393MB
gp6-nginx-image     latest              7b228a928b93        About an hour ago    126MB
tomcat              8-jdk8-openjdk      ed94f55483b8        3 days ago           507MB
redis               latest              9b188f5fb1e6        4 days ago           98.2MB
nginx               latest              f7bb5701a33c        9 days ago           126MB
centos              7                   5e35e350aded        8 weeks ago          203MB


你可能感兴趣的:(11 Dockerfile构建jdk1.8镜像)