1设置基础镜像 

$ FROM  centos:latest    (如果不加:latest默认是最新的)

2设置维护者 


$ MAINTAINER "xiajinlu"<xiajinlu1990@163.com>


3挂载文件

$ ADD  jdk-8u51-linux-x64.rpm  /opt   (放到Dockerfile下)

4.执行文件

$ RUN rpm -ivh /opt/jdk1.8.rpm(亲测代码《Dockerfile》文件)

FROM centos
MAINTAINER  "xiajinlu"<xiajinlu1990@163.com>
ADD /opt/jdk-8u51-linux-x64.rpm  /opt
RUN rpm -rpm -ivh /opt/jdk-8u51-linux-x64.rpm

5执行文件构建镜像

[root@VM_0_3_centos docker]# docker build -t  xiaojinlu/java .
Sending build context to Docker daemon 152.2 MB
Step 1/4 : FROM centos
 ---> 5182e96772bf
Step 2/4 : MAINTAINER "xiajinlu"<xiajinlu1990@163.com>
 ---> Using cache
 ---> 1f70ba4711ca
Step 3/4 : ADD jdk-8u51-linux-x64.rpm /opt
 ---> Using cache
 ---> 678953fdfeb2
Step 4/4 : RUN rpm  -ivh /opt/jdk-8u51-linux-x64.rpm
 ---> Running in a50c7b2ded8f

Preparing...                          ########################################
Updating / installing...
jdk1.8.0_51-2000:1.8.0_51-fcs         ########################################
Unpacking JAR files...
	rt.jar...
	jsse.jar...
	charsets.jar...
	tools.jar...
	localedata.jar...
	jfxrt.jar...
	plugin.jar...
	javaws.jar...
	deploy.jar...
 ---> 2dc42accd0fa
Removing intermediate container a50c7b2ded8f
Successfully built 2dc42accd0fa

测试

[root@VM_0_3_centos docker]# docker run -i -t   2dc42accd0fa /bin/bash
[root@33f00d74e6eb /]# java 
Usage: java [-options] class [args...]
           (to execute a class)
   or  java [-options] -jar jarfile [args...]
           (to execute a jar file)
where options include:
    -d32	  use a 32-bit data model if available
    -d64	  use a 64-bit data model if available
    -server	  to select the "server" VM
                  The default VM is server.

    -cp <class search path of directories and zip/jar files>
    -classpath <class search path of directories and zip/jar files>
                  A : separated list of directories, JAR archives,
                  and ZIP archives to search for class files.
    -D<name>=<value>
                  set a system property
    -verbose:[class|gc|jni]
                  enable verbose output
    -version      print product version and exit
    -version:<value>
                  require the specified version to run
    -showversion  print product version and continue
    -jre-restrict-search | -no-jre-restrict-search
                  include/exclude user private JREs in the version search
    -? -help      print this help message
    -X            print help on non-standard options
    -ea[:<packagename>...|:<classname>]
    -enableassertions[:<packagename>...|:<classname>]
                  enable assertions with specified granularity
    -da[:<packagename>...|:<classname>]
    -disableassertions[:<packagename>...|:<classname>]
                  disable assertions with specified granularity
    -esa | -enablesystemassertions
                  enable system assertions
    -dsa | -disablesystemassertions
                  disable system assertions
    -agentlib:<libname>[=<options>]
                  load native agent library <libname>, e.g. -agentlib:hprof
                  see also, -agentlib:jdwp=help and -agentlib:hprof=help
    -agentpath:<pathname>[=<options>]
                  load native agent library by full pathname
    -javaagent:<jarpath>[=<options>]
                  load Java programming language agent, see java.lang.instrument
    -splash:<imagepath>
                  show splash screen with specified image
See http://www.oracle.com/technetwork/java/javase/documentation/index.html for more details.