Docker:JDK镜像制作
1.下载JDKjdk-8u221-linux-x64.tar.gz2.创建Dockerfile新建一个jdk文件夹方便打包mkdir ~/jdk# 把jdk放进去chao@localhost:~$ cp jdk-8u221-linux-x64.tar.gz ./jdkchao@localhost:~$ cd jdkchao@localhost:~/jdk$ lsDock...
·
1.下载JDK
- jdk-8u221-linux-x64.tar.gz
2.创建Dockerfile
- 新建一个jdk文件夹方便打包
mkdir ~/jdk
# 把jdk放进去
chao@localhost:~$ cp jdk-8u221-linux-x64.tar.gz ./jdk
chao@localhost:~$ cd jdk
chao@localhost:~/jdk$ ls
Dockerfile jdk-8u221-linux-x64.tar.gz
chao@localhost:~/jdk$
- 进入jdk目录下,构建Dockerfile文件
# This is a JDK servic docker
FROM centos
MAINTAINER chao
ADD jdk-8u221-linux-x64.tar.gz /usr/local
ENV JAVA_HOME /usr/local/jdk1.8.0_221
ENV JRE_HOME /usr/local/jdk1.8.0_221/jre
ENV PATH $JAVA_HOME/bin:$PATH
3.使用Dockerfile构建jdk镜像
docker build -t jdk-8u221:v1 .
chao@localhost:~/jdk$ docker build -t jdk-8u221:v1 .
Sending build context to Docker daemon 195.1MB
Step 1/6 : FROM centos
latest: Pulling from library/centos
8ba884070f61: Pull complete
Digest: sha256:a799dd8a2ded4a83484bbae769d97655392b3f86533ceb7dd96bbac929809f3c
Status: Downloaded newer image for centos:latest
---> 9f38484d220f
Step 2/6 : MAINTAINER chao
---> Running in 87c21c7c62a9
Removing intermediate container 87c21c7c62a9
---> 31b77622d085
Step 3/6 : ADD jdk-8u221-linux-x64.tar.gz /usr/local
---> 5dfa5f52ec49
Step 4/6 : ENV JAVA_HOME /usr/local/jdk1.8.0_221
---> Running in 5ed62f87da4f
Removing intermediate container 5ed62f87da4f
---> 8fd8d26c0d6b
Step 5/6 : ENV JRE_HOME /usr/local/jdk1.8.0_221/jre
---> Running in ba9cc3d244c2
Removing intermediate container ba9cc3d244c2
---> 17e5e9f80934
Step 6/6 : ENV PATH $JAVA_HOME/bin:$PATH
---> Running in 23110c0fe897
Removing intermediate container 23110c0fe897
---> 87c2abc2bff8
Successfully built 87c2abc2bff8
Successfully tagged jdk-8u221:v1
4.查看镜像
chao@localhost:~/jdk$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
jdk-8u221 v1 87c2abc2bff8 47 seconds ago 609MB
centos latest 9f38484d220f 5 months ago 202MB
5.进入容器验证java环境
chao@localhost:~/jdk$ docker run -it jdk-8u221:v1 /bin/bash
[root@9bad7b732e5d /]# java -version
java version "1.8.0_221"
Java(TM) SE Runtime Environment (build 1.8.0_221-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.221-b11, mixed mode)
可看到,jdk镜像中的java环境已经配置完成
更多推荐
已为社区贡献3条内容
所有评论(0)