docker构建jdk1.8镜像
下载jdk1.8文件
新建目录 /dc/jdk8
, 将 jdk-8u45-linux-x64.tar.gz
下载到此目录,并创建 Dockerfile
文件:
[root@startsky jdk8]# tree
.
├── Dockerfile
└── jdk-8u45-linux-x64.tar.gz
Dockerfile配置文件
FROM docker.io/jeanblanchard/alpine-glibc
MAINTAINER zoe
RUN mkdir /usr/local/java/jdk
WORKDIR /usr/local/java/jdk
ADD jdk-8u45-linux-x64.tar.gz /usr/local/java/jdk
ENV JAVA_HOME /usr/local/java/jdk/jdk1.8.0_45
ENV PATH ${PATH}:${JAVA_HOME}/bin
构建镜像
在目录 /dc/jdk8
执行:
[root@startsky jdk8]# docker build -t jdk8 .
Sending build context to Docker daemon 173.3MB
Step 1/7 : FROM docker.io/jeanblanchard/alpine-glibc
....
Step 7/7 : ENV PATH ${PATH}:${JAVA_HOME}/bin
---> Running in 24953637b05f
Removing intermediate container 24953637b05f
---> 6e1fc4686009
Successfully built 6e1fc4686009
Successfully tagged jdk8:latest
查看镜像
[root@startsky jdk8]# docker image list
REPOSITORY TAG IMAGE ID CREATED SIZE
jdk8 latest 6e1fc4686009 13 seconds ago 359MB
wurstmeister/kafka latest 40094a582680 7 weeks ago 435MB
运行jdk8镜像
[root@startsky jdk8]# docker run -di --name=jdk8 jdk8
ef5d1bddf40bb4cf71360b23c8db223c21aabf98e132fe05350e79c92b1aaccb
[root@startsky jdk8]# docker exec -it jdk8 /bin/sh
/usr/local/java/jdk # java -version
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)