同级目录下创建一个Dockerfile,必须叫这个名字 [[email protected] file]# ll total 181296 -rw-r--r--. 1 root root 0 Oct 31 10:34 Dockerfile -rw-r--r--. 1 root root 185646832 Mar 28 2019 jdk-8u181-linux-x64.tar.gz 编写Dockerfile [[email protected] file]# vim Dockerfile [[email protected] file]# cat Dockerfile # 基于centos7,如果没有这个镜像那么它会下载这个镜像。 FROM centos:7 # 创建者(这个可以不写) MAINTAINER 吴磊 # 为Dockerfile中所有RUN、CMD、ENTRYPOINT、COPY和ADD指令设定工作目录 WORKDIR /usr # 执行命令(这里创建了一个目录) RUN mkdir /usr/local/java # 和copy一样,复制文件到指定目录,但是copy不能解压,add自动解压 ADD jdk-8u181-linux-x64.tar.gz /usr/local/java # 设置环境变量(不知道文件名可以现在宿主机解压后看一下) ENV JAVA_HOME /usr/local/java/jdk1.8.0_181 ENV JRE_HOME $JAVA_HOME/jre ENV CLASSPATH $JAVA_HOME/bin/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib:$CLASSPATH ENV PATH #JAVA_HOME/bin:$PATH 执行dockerfile文件,创建的镜像名为jdk1.8,最后面的点表示当前目录(即dockerfile所在目录) [[email protected] file]# docker build -t=‘jdk1.8‘ . Sending build context to Docker daemon 185.7MB Step 1/9 : FROM centos:7 ---> 67fa590cfc1c Step 2/9 : MAINTAINER 吴磊 ---> Running in 463fa71ed61d Removing intermediate container 463fa71ed61d ---> 688735620112 Step 3/9 : WORKDIR /usr ---> Running in fd1295dcef88 Removing intermediate container fd1295dcef88 ---> 21de4cf7978d Step 4/9 : RUN mkdir /usr/local/java ---> Running in 664aa88a0984 Removing intermediate container 664aa88a0984 ---> 89e5d852cbb3 Step 5/9 : ADD jdk-8u181-linux-x64.tar.gz /usr/local/java ---> f21dc033c80a Step 6/9 : ENV JAVA_HOME /usr/local/java/jdk1.8.0_181 ---> Running in e013ce2a06e9 Removing intermediate container e013ce2a06e9 ---> c95cd67fda2d Step 7/9 : ENV JRE_HOME $JAVA_HOME/jre ---> Running in 2d10888a4dcd Removing intermediate container 2d10888a4dcd ---> 36e4346c5045 Step 8/9 : ENV CLASSPATH $JAVA_HOME/bin/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib:$CLASSPATH ---> Running in 697be4f29d3d Removing intermediate container 697be4f29d3d ---> 9e148990099d Step 9/9 : ENV PATH #JAVA_HOME/bin:$PATH ---> Running in 0fccaf805f73 Removing intermediate container 0fccaf805f73 ---> b591f5c69edd Successfully built b591f5c69edd Successfully tagged jdk1.8:latest 查看所有的镜像,此时就多了一个jdk1.8 [[email protected] file]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE jdk1.8 latest b591f5c69edd 17 seconds ago 584MB centos 7 67fa590cfc1c 2 months ago 202MB registry latest f32a97de94e1 7 months ago 25.8MB [[email protected] file]#
原文地址:https://www.cnblogs.com/wlwl/p/11774508.html
时间: 2024-09-29 00:09:53