Dockerfile

Introduction to the

  • Dockerfile profile
    • Dockerfile is the file used to build dokcer images! Command parameter script!
  • Build steps
    • Write a dockerFile file
    • Dockerbuild builds into an image
    • Dockerrun runs the image
    • Docker Push image release (DockerHub, Ali Cloud warehouse)
  • See how official is built
    • Click the red box to jump to the Github address
    • A lot of official images are base packages, and a lot of features are missing, so we usually build our own images
    • If the authorities can make mirrors, so can we
  • Dockerfile writing specification
    1. Each reserved keyword (instruction) must be in uppercase
    2. Execute from top to bottom
    3. # comment
    4. Each instruction creates and commits a new mirror layer, and commits
  • The far-reaching impact of Dockerfile
    1. Dockerfile is development oriented, we want to release the project later, do like, you need to write dockerfile file, this file is very simple!
    2. Docker image has gradually become the standard of enterprise delivery, must be mastered!
    3. Steps: Development, deployment, operation and maintenance… Both are indispensable!
      • DockerFiIe build file, defined all the steps, source code (their own development)
      • Dockerlmages through DockerFiIe build generated like, the final release and run the product! (use)
      • The Docker container is the server that the image runs on

Dockerfile instruction

In actual combat

  • Dockerfile command
FROM centos MAINTAINER waws<[email protected]> ENV MYPATH /usr/local WORKDIR @MYPATH RUN yum -y install vim RUN yum -y  install net-tools EXPOSE 80 CMD echo $MYPATH CMD echo "-------end-------" CMD /bin/bashCopy the code
  • Effect of installation process
Sending build context to Docker daemon 2.048kB Step 1/10: FROM centos---> 0d120b6ccaa8Step 2/10: MAINTAINER waws<[email protected]> # Author information---> Running in dd1d454e365b
Removing intermediate container dd1d454e365b
---> 0eb159a21f67Step 3: ENV MYPATH /usr/local---> Running in 4b61abda7759
Removing intermediate container 4b61abda7759
---> 2597f9cf4496Step 4: WORKDIR @mypath---> Running in 527632c7d29f
Removing intermediate container 527632c7d29f
---> d6cd1780dfb5Step 5: RUN yum -y install vim # download vim and nettools from the network---> Running in 5867417fe57aCentOS - 8-2.7 MB/s AppStream | 5.8 MB 00:02 CentOS - 8 - Base 2.0 MB/s | 2.2 MB 00:01onsaturday (UK time) CentOS - 8 - Extras | 8.1 kB of 7.4 kB/s  00:01 Dependencies resolved. ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: VIM-enhanced X86_64 2:8.0.1763-13. El8 AppStream 1.4 M Installing Dependencies: GPM -libs x86_64 1.20.7-15.el8 AppStream 39 k vim-common x86_64 2:8.0.1763-13.el8 AppStream 6.3 M vim-filesystem noarch 2. 8.0.1763-13. El8 AppStream 48 K which x86_64 2.21-12.el8 BaseOS 49 K Transaction Summary ================================================================================ Install 5 Packages Total download size: 7.8 M Installed size: 31 M Downloading Packages: (1/5) : GPM - libs - 1.20.7-15. El8. X86_64. RPM 37 kB/s | 39 kB 00:01onsaturday (UK time) (2/5) : Vim - filesystem - 8.0.1763-13. El8. Noarch. Rp 545 kB/s | 48 kB 00:00 (3/5) : Which - 2.21-12. El8. X86_64. RPM 49 kB 194 kB/s | 00:00 (4/5) : Vim - enhanced - 8.0.1763-13. El8. X86_64. RPM 771 kB/s | 1.4 MB 00:01onsaturday (UK time) (5/5) : Vim - common - 8.0.1763-13. El8. X86_64. RPM 1.3 MB/s | 6.3 MB 00:04 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- Total 1.2 MB/s | 7.8 MB 00:06 warning: The/var/cache/DNF/AppStream - 02 e86d1c976ab532 / packages/GPM - libs - 1.20.7-15. El8. X86_64. RPM: Header V3 RSA/SHA256 Signature, key ID 8483c65d: NOKEY CentOS - 8-1.6 MB/s AppStream | 1.6 kB 00:00 Importing GPG key 0 x8483c65d: Userid: "CentOS (CentOS Official Signing Key) <[email protected]>" Fingerprint: 99DB 70FA E1D7 CE22 7FB6 4882 05B5 55B3 8483 C65D From : /etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial Key imported successfully Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Preparing : 1/1 Installing : Which -2.21-12.el8.x86_64 1/5 Installing: VIM-filesystem -2:8.0.1763-13.el8.noarch 2/5 Installing: Vim-common-2:8.0.1763-13.el8.x86_64 3/5 Installing: GPM-LIBS-1.20.7-15.el8.x86_64 4/5 Running scriptlet: Gpm-libs-1.20.7-15.el8.x86_64 4/5 Installing: VIM-enhanced 2:8.0.1763-13.el8.x86_64 5/5 Running Scriptlet: Scriptlet: ViM-common-2:8.0.1763-13.el8.x86_64 5/5 Running Scriptlet: ViM-common-2:8.0.1763-13.el8.x86_64 5/5 Verifying: Gpm-libs-1.20.7-15.el8.x86_64 1/5 Verifying: vim-common-2:8.0.1763-13.el8.x86_64 2/5 Verifying: Vim-enhanced -2:8.0.1763-13.el8.x86_64 3/5 Verifying: vim-filesystem-2:8.0.1763-13.el8.noarch 4/5 Verifying: vim-enhanced-2:8.0.1763-13.el8.x86_64 3/5 Verifying: Which - 2.21-12. El8. 5/5 x86_64 Installed: GPM - libs - 1.20.7-15. El8. X86_64 vim - common - 2:8. 0.1763-13. El8. X86_64 vim - enhanced - 2:8. 0.1763-13. El8. X86_64 Vim filesystem - 2:8. 0.1763-13. El8. Noarch which - 2.21-12. El8. X86_64 Complete! Removing intermediate container 5867417fe57a---> c72800950e21
Step 6/10 : RUN yum -y install net-tools
---> Running in 09f5890b9264Last metadata expiration check: 0:00:12 ago on Sat Oct 3 09:46:06 2020. Dependencies resolved. ================================================================================ Package Architecture Version Repository  Size ================================================================================ Installing: Net Tools x86_64 2.0-0.51.20160912 Git. el8 BaseOS 323 K Transaction Summary ================================================================================ Install 1 Package Total download size: 323 K Installed size: 1.0m Downloading Packages: Downloading Net - tools - 2.0-0.51.20160912 git. El8. X86_64. | 323 kB 00:00 RPM 1.7 MB/s -------------------------------------------------------------------------------- Total 504 kB/s | 323 kB 00:00 Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Preparing: 1/1 Installing: NET-tools-2.0-0.51.20160912 Git.el8.x86_64 1/1 Running Scriptlet: Net-tools-2.0-0.51.20160912 git.el8.x86_64 1/1 Verifying: net-tools-2.0-0.51.20160912git.el8.x86_64 1/1 Installed: Net - tools - 2.0-0.51.20160912 git. El8. X86_64 Complete! Removing intermediate container 09f5890b9264---> cd3a6c56f9e6Step 7/10: EXPOSE 80 #---> Running in 5e71dc82b66d
Removing intermediate container 5e71dc82b66d
---> 7699d971e2deStep 8/10: CMD echo $MYPATH #---> Running in cd1156844880
Removing intermediate container cd1156844880
---> 5f62b3148180
Step 9/10 : CMD echo "-------end-------"
---> Running in 44fd371fabe7
Removing intermediate container 44fd371fabe7
---> fc4fcc5350bc
Step 10/10 : CMD /bin/bash
---> Running in 47d3d9910051
Removing intermediate container 47d3d9910051
---> b6b678359c7eSuccessfully built b6b678359C7e # Tag mycentos Successfully :latestCopy the code
  • Results show

Difference between CMD and ENTRYPOINT

  • CMD is the replacement command
    • The content of the dockerfile
      FROM centos
      CMD ["ls","-a"]
      Copy the code
    • The effect
  • ENTRYPOINT is the append command
    • The content of the dockerfile
      FROM centos
      ENTRYPOINT ["ls","-a"]
      Copy the code
    • The effect

Actual combat tomcat

  • First of all, prepare the files required by the image, tomcat installation package, JDK installation package (this place to download the line, pay attention to the corresponding numbers)
  • -f is not required to specify a dockerfile, which is officially named and automatically found by build
FROM centos MAINTAINER waws<[email protected]> COPY readme.txt /usr/local/readme.txt ADD jdk-8u101-linux-x64.tar.gz /usr/local/add apache-tomcat-9.0.27.tar.gz /usr/local/run yum -y install vim ENV MYPATH /usr/local/workdir $MYPATH ENV JAVA_HOME /usr/local/jdk1.8.0_101 ENV CATALINA_HOME /usr/local/apache-tomcat-9.0.27 ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/lib EXPOSE 8080 CMD /usr/local/apache-tomcat-9.0.27/bin/startup.sh && tail -f / usr/local/apache tomcat - 9.0.27 / logs/catalina. OutCopy the code
  • Build the mirror
    • Docker build -t diytomcat: 1.0
  • Boot image
    Docker run - d - p - 9090-8080 the name tomcat01 - v/home/test: / usr/local/apache tomcat - 9.0.27 / webapps/test - v / home/tomcatlogs /, / usr/local/apache tomcat - 9.0.27 / logs diytomcat: 1.0Copy the code
  • Publish the project (because of volume mount, we can write the project locally and publish it)