Java教程

Linux - Dockerfile - JDK

本文主要是介绍Linux - Dockerfile - JDK,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
# file list 

[22:43:27 root@centos7 jdk]#tree
.
├── Dockerfile
├── jdk-8u291-linux-x64.tar.gz
└── profile

0 directories, 3 files


# download jdk packages from oracle
# copy centos7:/etc/profile , add below 4 lines

[22:46:35 root@centos7 jdk]#tail -5 profile
export JAVA_HOME=/usr/local/jdk
export TOMCAT_HOME=/apps/tomcat
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$TOMCAT_HOME/bin:$PATH
export CLASSPATH=.$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/lib/tools.jar


# edit Dockerfile
[22:47:19 root@centos7 jdk]#cat Dockerfile 
FROM centos7-base:v2
LABEL maintainer="noise <root@noise.com>"
ADD jdk-8u291-linux-x64.tar.gz /usr/local/src
RUN ln -s /usr/local/src/jdk1.8.0_291 /usr/local/jdk
ADD profile /etc/profile
ENV JAVA_HOME /usr/local/jdk
ENV JRE_HOME $JAVA_HOME/jre
ENV CLASSPATH $JAVA_HOME/lib/:$JRE_HOME/lib/
ENV PATH $PATH:$JAVA_HOME/bin

# docker  build 
[22:41:06 root@centos7 jdk]#docker build -t jdk:v2.0 .

[22:41:15 root@centos7 jdk]#docker images
REPOSITORY                      TAG              IMAGE ID       CREATED          SIZE
jdk                             v2.0             e1ef0c699afa   4 seconds ago    708MB

# docker run to check if jdk is installed successfully
[22:41:19 root@centos7 jdk]#docker run -it jdk:v2.0 bash
[root@344f5caf88ee /]# java -version
java version "1.8.0_291"
Java(TM) SE Runtime Environment (build 1.8.0_291-b10)
Java HotSpot(TM) 64-Bit Server VM (build 25.291-b10, mixed mode)
[root@344f5caf88ee /]# exit
exit

# push to harbor
[22:41:43 root@centos7 jdk]#docker tag jdk:v2.0 10.0.0.101/example/jdk:v2.0

[22:42:43 root@centos7 jdk]#docker push 10.0.0.101/example/jdk:v2.0
The push refers to repository [10.0.0.101/example/jdk]
193267eb9d23: Pushed 
9f7b8adad2b1: Pushed 
496063d1b0f4: Pushed 
7b578e484e37: Pushed 
764e12176167: Pushed 
034f282942cd: Pushed 
v2.0: digest: sha256:b7b5863b67bbe0228da549df1b79d8c8a6be62627747d41f843d2e18b160a092 size: 1577

 

这篇关于Linux - Dockerfile - JDK的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!