Docker use - two hours to get started

Posted by nosher on Sat, 09 Nov 2019 12:52:47 +0100

  • Welcome to the original link: https://mp.weixin.qq.com/s/eAJpnEfjflVr76iPVHN6rA 
  • This is a personal note of sorting and thinking after watching the above links
  •  
  • Advantages of docker container
    • More efficient use of system resources
      • Because the container does not need additional overhead such as hardware virtualization and running a complete operating system, Docker has a higher utilization of system resources.
      • Whether it is application execution speed, memory loss or file storage speed, it is more efficient than traditional virtual machine technology. Therefore, compared with virtual machine technology, a host with the same configuration can often run more applications.
    • Faster startup time
      • Traditional virtual machine technology usually takes several minutes to start application services, while Docker container application, because it runs directly in the host kernel, does not need to start the complete operating system, so it can achieve the start-up time of seconds or even milliseconds. It greatly saves the time of development, testing and deployment.
    • Consistent operating environment
      • A common problem in the development process is environment consistency. Due to the inconsistency of development environment, test environment and production environment, some bug s are not found in the development process.
      • The Docker image provides a complete runtime environment other than the kernel, which ensures the consistency of the application running environment, so there will be no such problems as "this code is OK on my machine".
    • Continuous delivery and deployment
      • For development and operation and maintenance (DevOps) personnel, the most desirable thing is to create or configure it once, and it can run normally anywhere.
      • Docker can be used to achieve continuous integration, delivery and deployment by customizing the application image. Developers can build the image through Dockerfile and conduct integration test in combination with continuous integration system, while operation and maintenance personnel can quickly deploy the image directly in the production environment, or even automatically deploy it in combination with continuous delivery / deployment system.
      • In addition, Dockerfile is used to make the image construction transparent. Not only the development team can understand the application operation environment, but also the operation and maintenance team can understand the conditions required for application operation, so as to help the better production environment to deploy the image.
    • Easier migration
      • Because docker ensures the consistency of execution environment, it makes application migration easier. Docker can run on many platforms, whether it is a physical machine, a virtual machine, a public cloud, a private cloud, or even a notebook, and the results are consistent.
      • Therefore, users can easily migrate the applications running on one platform to another without worrying about the situation that the application cannot run normally due to the change of the running environment.
  • Introduction to docker
    • docker command
      • Usage:
        docker [OPTIONS] COMMAND [arg...]
               docker daemon [ --help | ... ]
               docker [ --help | -v | --version ]
        A
        self-sufficient runtime for containers.
        
        Options:
          --config=~/.docker              Location of client config files  #Location of client profile
          -D, --debug=false               Enable debug mode  #Enable Debug debugging mode
          -H, --host=[]                   Daemon socket(s) to connect to  #Socket connection of Daemons
          -h, --help=false                Print usage  #Print use
          -l, --log-level=info            Set the logging level  #Set log level
          --tls=false                     Use TLS; implied by--tlsverify  #
          --tlscacert=~/.docker/ca.pem    Trust certs signed only by this CA  #Trust certificate signing CA
          --tlscert=~/.docker/cert.pem    Path to TLS certificate file  #TLS certificate file path
          --tlskey=~/.docker/key.pem      Path to TLS key file  #TLS key file path
          --tlsverify=false               Use TLS and verify the remote  #Remote authentication using TLS
          -v, --version=false             Print version information and quit  #Print version information and exit
        
        Commands:
            attach    Attach to a running container  #The attach connection under the current shell specifies the running image
            build     Build an image from a Dockerfile  #Customizing image through Dockerfile
            commit    Create a new image from a container's changes  #Commit the current container as a new mirror
            cp    Copy files/folders from a container to a HOSTDIR or to STDOUT  #Copy the specified file or directory from the container to the host
            create    Create a new container  #Create a new container, the same as run but do not start the container
            diff    Inspect changes on a container's filesystem  #View docker container changes
            events    Get real time events from the server#Get container real-time events from docker service
            exec    Run a command in a running container#Run command on an existing container
            export    Export a container's filesystem as a tar archive  #Export the content stream of the container as a tar Archive (corresponding to import)
            history    Show the history of an image  #Show the history of the formation of a mirror image
            images    List images  #List the current image of the system
            import    Import the contents from a tarball to create a filesystem image  #Create a new file system image from the contents of the tar package (corresponding to export)
            info    Display system-wide information  #Display system related information
            inspect    Return low-level information on a container or image  #View container details
            kill    Kill a running container  #kill specifies the docker container
            load    Load an image from a tar archive or STDIN  #Load a mirror from a tar package (corresponding to save)
            login    Register or log in to a Docker registry#Register or log in to a docker source server
            logout    Log out from a Docker registry  #Exit from the current Docker registry
            logs    Fetch the logs of a container  #Output current container log information
            pause    Pause all processes within a container#Pause container
            port    List port mappings or a specific mapping for the CONTAINER  #View the container internal source port corresponding to the mapped port
            ps    List containers  #List containers
            pull    Pull an image or a repository from a registry  #Pull the specified image or library image from the docker image source server
            push    Push an image or a repository to a registry  #Push the specified image or library image to the docker source server
            rename    Rename a container  #Rename container
            restart    Restart a running container  #Restart running container
            rm    Remove one or more containers  #Remove one or more containers
            rmi    Remove one or more images  #Remove one or more mirrors (the mirror can only be deleted if there is no container, otherwise the related containers need to be deleted before continuing or - f forces deletion)
            run    Run a command in a new container  #Create a new container and run a command
            save    Save an image(s) to a tar archive#Save an image as a tar package (corresponding to load)
            search    Search the Docker Hub for images  #Searching for images in dockerhub
            start    Start one or more stopped containers#Starting container
            stats    Display a live stream of container(s) resource usage statistics  #Statistics container usage resources
            stop    Stop a running container  #Stop container
            tag         Tag an image into a repository  #Label the image in the source
            top       Display the running processes of a container #View process information running in the container
            unpause    Unpause all processes within a container  #Unsuspend container
            version    Show the Docker version information#View container version number
            wait         Block until a container stops, then print its exit code  #Intercepts the exit status value when the container stops
        
        Run 'docker COMMAND --help' for more information on a command.  #You can get more information by running the docker command in help

         

    • docker operation and maintenance
      • docker run create container

        • For example, if I want to start a centos container, the host's / test directory can be attached to the container's / soft directory, which can be specified in the following ways:

        • docker run -it -v /test:/soft centos /bin/bash

      • docker update update docker configuration

        • Modify container to auto start

        • docker container update --restart=always container name

      •  

        docker exec enters the container

        • Enter container internal command

        • docker exec -it container id /bin/bash

      • docker ps -s view container size

      •  

         

         

  • docker upgrade
    • dockerFile
      • Introduction to dockerFile syntax
      • https://www.cnblogs.com/dance-walter/p/9581508.html
      • dockerFile common instructions
        • FROM specifies the base image
          RUN execute command
          RUN, such as RUN echo '< H1 > Hello, docker! < H1 >' > / usr / share / nginx / HTML / index.html
          RUN [executable, Parameter1, parameter2]
          COPY copy file
          Copy [-- chown = < user >: < group >] ["< source path 1 >", "..." < target path > "]
          The source path can be multiple, or even wildcard, and its wildcard rule should meet the filepath.Match rule of Go
          ADD more advanced copy file
          ADD and COPY are basically the same. The difference is that if the ADD source path can be a url, and if the < source path > is a tar compressed file, and the compression format is gzip, bzip2 and xz, the ADD instruction will automatically decompress the compressed file to < target path >.
          In the official Dockerfile best practice document of Docker, it is required to use COPY as much as possible, because the semantics of COPY is very clear, that is, copying files, while ADD contains more complex functions, and its behavior is not necessarily very clear. The most suitable situation to use ADD is the one mentioned that needs automatic decompression.
          CMD container start command
          ENTRYPOINT entry point
          The purpose of ENTRYPOINT is the same as that of CMD, which specifies the container startup program and parameters.
          When ENTRYPOINT is specified, the meaning of CMD changes. Instead of running its command directly, the content of CMD is passed to the ENTRYPOINT command as a parameter
          ENV setting environment variable
          ARG build parameters
          VOLUME define anonymous VOLUME
          EXPOSE port

           

      • Simple and practical dockerFile
      • https://www.cnblogs.com/jhxxb/p/11445594.html
      •     
    • Continuous delivery of docker
    • Continuous integration of docker
    • Continuous deployment of docker
    • The above can be viewed by a third party: Building continuous deployment on containers and best practices
  • Points for docker use and attention
    •  
  • End (scatter flowers)
    • Continuous update

Topics: Programming Docker socket CentOS shell