# 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
原文:https://www.cnblogs.com/noise/p/14864870.html