I met Dockerfile

Dockerfile profile

Dockerfile is used to build docker image file! Command script! First experience. Through this script can generate mirror, mirror is a layer of a layer, script is a command, each command is a layer! Write a dockerfile

Create a file named dockerFile
# Content directive (uppercase) arguments in the file
FROM centos 
VOLUME ["volme01"."volume02"] 
CMD echo "--------end----------" 
CMD /bin/bash 
Here each instruction is a mirror layer
Copy the code

Use dockerfile to generate the image

Docker build -f Dockerfile file location -t Image name and location where the version image is generatedCopy the code

  • View details about the image

  • View the volume synchronization directory
    • docker ps -a
    • Docker inspect Container ID
  • Finally, test whether the two folders are synchronized
    • Synchronous success
  • conclusion
    • The way to build images using Dockerfile is going to be a lot more common in our future use, because we will usually build our own images
    • If no volume is mounted during mirror construction, manually mount the image -v

Dockerfile,

  • 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, do the image, 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!
      1. DockerFiIe build file, defined all the steps, source code (their own development)
      2. Dockerlmages through DockerFiIe build generated like, the final release and run the product! (use)
      3. Docker container the container is the server that the image runs on (use)
    • Dockerfile instruction

In actual combat

Dockerfile command

FROM centos 
MAINTAINER waws<16601203140@163.com> 
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/bash 
Copy the code
  • Effect of installation process
Sending build context to Docker daemon  2.048kB 
Step 1/10 : FROM centos                                              Install from centos
---> 0d120b6ccaa8 
Step 2/10 : MAINTAINER waws<16601203140@163.com>                     # Author information
---> Running in dd1d454e365b 
Removing intermediate container dd1d454e365b 
---> 0eb159a21f67 
Step 3/10 : ENV MYPATH /usr/local                                      # Environment variables
---> Running in 4b61abda7759 
Removing intermediate container 4b61abda7759 
---> 2597f9cf4496 
Step 4/10 : WORKDIR @MYPATH                                            Set the working directory
---> Running in 527632c7d29f 
Removing intermediate container 527632c7d29f 
---> d6cd1780dfb5 
Step 5/10 : RUN yum -y install vim                                    # Download Vim and Net-Tools from the web
---> Running in 5867417fe57a 
CentOS-8- AppStream                                                        2.7 MB/s | 5.8MB        00: 02         CentOS -8- Base                                                                2.0 MB/s | 2.2MB        00: 01         CentOS -8- Extras                                                            7.4 kB/s | 8.1KB        00: 01         Dependencies resolved. = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = Package                         Arch                 Version                                     Repository             Size ================================================================================ Installing: Vim - enhanced                 x86_64            2:8.01763.-13.El8                 AppStream            1.4M Installing dependencies: GPM - libs                         x86_64            1.207.-15.El8                         AppStream            39K vim - common                     x86_64            2:8.01763.-13.El8                 AppStream            6.3M vim - filesystem             noarch            2:8.01763.-13.El8                 AppStream            48K which                             x86_64            2.21-12.El8                             BaseOS                    49K the Transaction Summary = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = the Install    5 Packages 

Total download size: 7.8 M 
Installed size: 31 M 
Downloading Packages: 
(1/5): gpm-libs-1.207.-15.El8. X86_64. RPM                37KB/s |    39KB        00: 01         (2/5): vim-filesystem-8.01763.-13.el8.noarch.rp 545KB/s |    48KB        00:00        (3/5): which-2.21-12.El8. X86_64. RPM                        194KB/s |    49KB        00:00        (4/5): vim-enhanced-8.01763.-13.El8. X86_64. RPM    771 kB/s | 1.4MB        00: 01         (5/5): vim-common-8.01763.-13.El8. X86_64. RPM        1.3 MB/s | 6.3MB        00: 04         -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- Total                                                                                    1.2 MB/s | 7.8MB        00: 06         warning: / var/cache/DNF/AppStream - 02 e86d1c976ab532 / packages/GPM - libs -1.207.-15.el8.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 8483c65d: NOKEY 
CentOS-8- AppStream                                                        1.6 MB/s | 1.6KB        00:00        Importing GPG key0x8483C65D: Userid         :"CentOS (CentOS Official Signing Key) <[email protected]>" 
Fingerprint: 99DB 70FA E1D7 CE22 7FB6 4882 05B5 55B3 8483C65D 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 -- filesystem2:8.01763.-13.El8. Noarch                                2/5    Installing             : vim - common -2:8.01763.-13.El8. X86_64                                        3/5    Installing             : GPM - libs -1.207.-15.El8. X86_64                                                    4/5    Running scriptlets: GPM - libs -1.207.-15.El8. X86_64                                                    4/5    Installing             : vim - enhanced -2:8.01763.-13.El8. X86_64                                    5/5    Running scriptlets: vim - enhanced -2:8.01763.-13.El8. X86_64                                    5/5    Running scriptlets: vim - common -2:8.01763.-13.El8. X86_64                                        5/5    Verifying                 : GPM - libs -1.207.-15.El8. X86_64                                                    1/5    Verifying                 : vim - common -2:8.01763.-13.El8. X86_64                                        2/5    Verifying                 : vim - enhanced -2:8.01763.-13.El8. X86_64                                    3/5    Verifying                 : vim -- filesystem2:8.01763.-13.El8. Noarch                                4/5    Verifying                 : which -2.21-12.El8. X86_64                                                            5/5Installed:     GPM - libs -1.207.-15.El8. X86_64                 vim - common -2:8.01763.-13.El8. X86_64             vim - enhanced -2:8.01763.-13.el8.x86_64 vim-filesystem-2:8.01763.-13.El8. Noarch     which -2.21-12.El8. X86_64                         Complete! Removing intermediate container 5867417fe57a ---> c72800950e21 Step6/10 : RUN yum -y install net-tools 
---> Running in 09f5890b9264 
Last metadata expiration check: 0:00:12A line on the Sat Oct    3 09:46: 062020.Dependencies resolved. = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = Package                 Architecture Version                                                 Repository         Size ================================================================================ Installing: Net - tools             x86_64            2.0-0.5120160912.Git. El8             BaseOS            323K the Transaction Summary = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = the Install    1 Package 

Total download size: 323 k 
Installed size: 1.0 M 
Downloading Packages: 
net-tools-2.0-0.5120160912.Git. El8. X86_64. RPM    1.7 MB/s | 323KB        00:00     -------------------------------------------------------------------------------- Total                                                                                    504 kB/s | 323KB        00:00     Running Transaction check Transaction check succeeded. Running Transaction test Transaction test succeeded. Running The transaction     Preparing                 :                                                                                                                1/1    Installing             : net - tools -2.0-0.5120160912.Git. El8. X86_64                            1/1    Running scriptlets: net - tools -2.0-0.5120160912.Git. El8. X86_64                            1/1    Verifying                 : net - tools -2.0-0.5120160912.Git. El8. X86_64                            1/1Installed:     net - tools -2.0-0.5120160912.Git. El8. X86_64                                                                         Complete! Removing intermediate container 09f5890b9264 ---> cd3a6c56f9e6 Step7/10 : EXPOSE 80                                                 Expose port 80
---> Running in 5e71dc82b66d 
Removing intermediate container 5e71dc82b66d 
---> 7699d971e2de 
Step 8/10 : CMD echo $MYPATH                                          # execute command
---> 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 
---> b6b678359c7e 
Successfully built b6b678359c7e                                        # Build success signs
Successfully tagged mycentos:latest 
Copy the code
  • Results show

Difference between CMD and ENTRYPOINT

  • CMD is the replacement command
FROM centos 
CMD ["ls"."-a"] exit
Copy the code
  • The effect
  • ENTRYPOINT is the append command
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<16601203140@163.com> 
COPY readme.txt /usr/local/readme.txt 
ADD jdk-8u101-linux-x64.tar.gz /usr/local/ 
ADD apache-tomcat-9.027..tar.gz /usr/local/ 
RUN yum -y install vim 
ENV MYPATH /usr/local 
WORKDIR $MYPATH 
ENV JAVA_HOME /usr/local/jdk18.. 0 _101 
ENV CATALINA_HOME /usr/local/apache-tomcat-9.027. 
ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/lib 
EXPOSE 8080 
CMD /usr/local/apache-tomcat-9.027./bin/startup.sh && tail -F /usr/local/apache-tomcat-9.027./logs/catalina.out 
Copy the code
  • Build the mirror

    • Docker build -t diytomcat: 1.0
  • Boot image

    • docker run -d -p 9090:8080 --name tomcat01 -v /home/test:/usr/local/apache-tomcat-9.027./webapps/test -v /home/tomcatlogs/:/usr/local/apache-tomcat-9.027./logs diytomcat:1.0 
      Copy the code
  • Publish the project (because of volume mount, we can write the project locally and publish it)

Publish your own Docker image

  • Published to dockerhub

    • Dockerhub address: hub.docker.com/ register your account

    • Make sure you can log in to this account

      • Login success – is displayed
    • Submit your own image on our server

    • After login, you can submit the image, which is a Docker push

      • root@iZbp12kyfwxfku3288sr59Z:/home# docker login --help 
        Usage:  docker login [OPTIONS] [SERVER] 
        
        Log in to a Docker registry. 
        If no server is specified, the default isDefined by the daemon. Options:   -p, --password string   password password       --password-stdin    Take the passwordfromStdin   -u, --username string   username usernameCopy the code
    • Login successful

      • root@iZbp12kyfwxfku3288sr59Z:/home# docker login -u waws520 login command
        Password:  
        WARNING! Your password will be stored unencrypted in /root/.docker/config.json. 
        Configure a credential helper to remove this warning. See 
        https://docs.docker.com/engine/reference/commandline/login/#credentials-store Login Succeeded The Login succeedsCopy the code
    • commit

      • The premise of submission is that the tag of our image must start with our username, otherwise the submission will be rejected
        • denied: requested access to the resource is denied
          • 1 login to docker login
          • 2 Check whether the tag contains a user name
        • First we relabel it
          • Docker Tag Image ID WAWS520 /my_image:1.0
          • Docker push waws520 / my_image: 1.0
          • Are uploading
          • Uploaded successfully
        • Commit by layer

Publish to Aliyun

  • Log in to Aliyun

  • Find the Mirror service

  • Creating a namespace

  • Create a warehouse

  • Detailed steps

      • Login successful
      • Change the version number and upload

Compressed package

  • Save
  • Load