Dockfile file parsing

1. Dockerfile those basics

  • Each instruction must be reserved words in capital letters and followed by at least one parameter to follow
  • Instruction is executed in top-down order
  • #It indicates a comment
  • Each command will create a new image layer, and mirror commit

2. Docker perform substantially the flow of Dockerfile

  • docker run from a container base image
  • Execute an instruction and container make changes
  • Docker commit operation is performed similar to submit a new image layer
  • docker again based mirroring run just submitted a new container
  • Dockerfile execution of the next instruction until all instructions execute complete

3. DockerFile Architecture (reserved word instruction)

  • FROM: base image, a new image is based on which the current mirror
  • MAINTAINER: Mirror defenders name and e-mail address
  • RUN: Run command is required when building container
  • EXPOSE: Foreign exposed current container port
  • WORKDIR: After you create a designated container terminal default landing came in the working directory, a foothold
  • ENV: used to construct the mirrors during set environment variables (ENV MY_PATH / usr / mytest)
  • ADD: the host file in the directory image and copied into the ADD command processing URL and automatically extract the tar archive
  • COPY: Similar ADD, copy files and directories to the mirror. Building context file directory from <source path> / directory to <destination path> location (COPY src dest) within the new mirror layer (COPY [ "src", "dest"])
  • VOLUME: container volume data, for data storage and persistence work
  • CMD: Specifies the command to start a container to run. There can be multiple CMD command, but only the last one will work, CMD parameter will be replaced after the docker run
  • ENTRYPOINT: Specifies the command to start a container to run, ENTRYPOINT purpose and CMD, are in the specified container and start the program parameters
  • ONBUILD: Run command when building an inherited Dockerfile, the father of the mirror is triggered after the quilt in his father's image of onbuild

Example 4. Content

FROM         centos
MAINTAINER    zzyy<zzyybs@126.com>
#把宿主机当前上下文的c.txt拷贝到容器/usr/local/路径下
COPY c.txt /usr/local/cincontainer.txt #把java与tomcat添加到容器中 ADD jdk-8u171-linux-x64.tar.gz /usr/local/ ADD apache-tomcat-9.0.8.tar.gz /usr/local/ #安装vim编辑器 RUN yum -y install vim #设置工作访问时候的WORKDIR路径,登录落脚点 ENV MYPATH /usr/local WORKDIR $MYPATH #配置java与tomcat环境变量 ENV JAVA_HOME /usr/local/jdk1.8.0_171 ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar ENV CATALINA_HOME /usr/local/apache-tomcat-9.0.8 ENV CATALINA_BASE /usr/local/apache-tomcat-9.0.8 ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/lib:$CATALINA_HOME/bin #容器运行时监听的端口 EXPOSE 8080 #启动时运行tomcat # ENTRYPOINT ["/usr/local/apache-tomcat-9.0.8/bin/startup.sh" ] # CMD ["/usr/local/apache-tomcat-9.0.8/bin/catalina.sh","run"] CMD /usr/local/apache-tomcat-9.0.8/bin/startup.sh && tail -F /usr/local/apache-tomcat-9.0.8/bin/logs/catalina.out
 

1. Dockerfile those basics

  • Each instruction must be reserved words in capital letters and followed by at least one parameter to follow
  • Instruction is executed in top-down order
  • #It indicates a comment
  • Each command will create a new image layer, and mirror commit

2. Docker perform substantially the flow of Dockerfile

  • docker run from a container base image
  • Execute an instruction and container make changes
  • Docker commit operation is performed similar to submit a new image layer
  • docker again based mirroring run just submitted a new container
  • Dockerfile execution of the next instruction until all instructions execute complete

3. DockerFile Architecture (reserved word instruction)

  • FROM: base image, a new image is based on which the current mirror
  • MAINTAINER: Mirror defenders name and e-mail address
  • RUN: Run command is required when building container
  • EXPOSE: Foreign exposed current container port
  • WORKDIR: After you create a designated container terminal default landing came in the working directory, a foothold
  • ENV: used to construct the mirrors during set environment variables (ENV MY_PATH / usr / mytest)
  • ADD: the host file in the directory image and copied into the ADD command processing URL and automatically extract the tar archive
  • COPY: Similar ADD, copy files and directories to the mirror. Building context file directory from <source path> / directory to <destination path> location (COPY src dest) within the new mirror layer (COPY [ "src", "dest"])
  • VOLUME: container volume data, for data storage and persistence work
  • CMD: Specifies the command to start a container to run. There can be multiple CMD command, but only the last one will work, CMD parameter will be replaced after the docker run
  • ENTRYPOINT: Specifies the command to start a container to run, ENTRYPOINT purpose and CMD, are in the specified container and start the program parameters
  • ONBUILD: Run command when building an inherited Dockerfile, the father of the mirror is triggered after the quilt in his father's image of onbuild

Example 4. Content

FROM         centos
MAINTAINER    zzyy<zzyybs@126.com>
#把宿主机当前上下文的c.txt拷贝到容器/usr/local/路径下
COPY c.txt /usr/local/cincontainer.txt #把java与tomcat添加到容器中 ADD jdk-8u171-linux-x64.tar.gz /usr/local/ ADD apache-tomcat-9.0.8.tar.gz /usr/local/ #安装vim编辑器 RUN yum -y install vim #设置工作访问时候的WORKDIR路径,登录落脚点 ENV MYPATH /usr/local WORKDIR $MYPATH #配置java与tomcat环境变量 ENV JAVA_HOME /usr/local/jdk1.8.0_171 ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar ENV CATALINA_HOME /usr/local/apache-tomcat-9.0.8 ENV CATALINA_BASE /usr/local/apache-tomcat-9.0.8 ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/lib:$CATALINA_HOME/bin #容器运行时监听的端口 EXPOSE 8080 #启动时运行tomcat # ENTRYPOINT ["/usr/local/apache-tomcat-9.0.8/bin/startup.sh" ] # CMD ["/usr/local/apache-tomcat-9.0.8/bin/catalina.sh","run"] CMD /usr/local/apache-tomcat-9.0.8/bin/startup.sh && tail -F /usr/local/apache-tomcat-9.0.8/bin/logs/catalina.out

Guess you like

Origin www.cnblogs.com/jians/p/11941215.html