Docker image principle basis and dockerfile deploy springboot project

1. Docker image principle

1. Operating system components

Process Scheduling Subsystem
Process Communication Subsystem
Memory Management Subsystem
Device Management Subsystem
File Management Subsystem
Network Communication Subsystem
Job Control Subsystem

The Linux file system consists of two parts: bootfs and rootfs
bootfs: including bootloader (boot loader) and kernel (kernel)
rootfs: root file system, including /dev, /proc, /bin, /etc, etc. in a typical Linux system Standard directories and files
Different linux distributions, the bootfs is basically the same, but the rootfs is different, such as ubuntu, centos, etc.

2. Docker image principle

  • Docker images are superimposed by a special file system
  • The bottom is bootfs and uses the host's bootfs
  • The second layer is the root file system rootfs, called base image
  • Then you can stack other image files on top
  • The Union File System technology can integrate different layers into one file system, providing a unified perspective for these layers, thus hiding the existence of multiple layers. From the user's point of view, there is only one file. system
  • An image can be placed on top of another image. The image below is called the parent image, and the bottom image becomes the base image
  • When launching a container from an image, Docker mounts a read-write filesystem at the top level as the container
    insert image description here

3. The essence of the docker image
is a layered file system

In the case
of Docker, why is a centos image only 200MB, and the iso file of a centos operating system needs several Gs?
The iso image file of Centos contains bootfs and rootfs, while the centos image of docker reuses the bootfs of the operating system, only rootfs and other image layers
. Why does a tomcat image in Docker have 500MB, while a tomcat installation package is only more than 70MB?
Since the images in docker are layered, although tomcat only has more than 70 MB, it needs to rely on the parent image and the base image. The size of all exposed tomcat images is more than 500 MB.

4. Mirror production

Containers are converted to images

docker commit 容器id 镜像名称:版本号

compressed image

docker save -o 压缩文件名称 镜像名称:版本号

Unzip the image archive

docker load –i 压缩文件名称

2. Dockerfile concept

1. Definition

  • dockerfile is a text file used to build images
  • The text contains the instructions and instructions needed to build the image
  • Each instruction for one layer, based on the base image, finally builds a new image
  • For developers: can provide a completely consistent development environment for the development team
  • For testers: you can directly take the image built during development or build a new image through the Dockerfile file to start working
  • For operation and maintenance personnel: seamless migration of applications can be achieved during deployment

2. dockerfile keyword

keywords effect Remark
FROM specify parent image Specifies that the dockerfile is based on which image to build
MAINTAINER author information Used to indicate who wrote this dockerfile
LABEL Label The label used to indicate the dockerfile can use Label instead of the Maintainer, which can be viewed in the basic information of the docker image
RUN Excuting an order Execute a command by default in /bin/sh format: RUN command or RUN [“command” , “param1”, “param2”]
CMD container start command Provides the default command to use with ENTRYPOINT when starting the container. Format CMD command param1 param2 or CMD ["command" , "param1", "param2"]
ENTRYPOINT Entrance Generally used in making some containers that are closed after execution
COPY copy file Copy the file to the image when building
ADD add files Adding files to the image during build is not limited to the current build context and can come from remote services
ENV environment variable The environment variable when specifying the build can be overridden in the format ENV name=value through -e when the container is started
ARG build parameters Build parameters are only used at build time. If there is ENV, then the value of the same name of ENV always overrides the parameter of arg
VOLUME Define externally mountable data volumes Specify those directories of the build image that can be started and mounted to the file system. When starting the container, use the -v binding format VOLUME ["directory"]
EXPOSE exposed port Define the port listening when the container is running Start the container using -p to bind the exposed port format: EXPOSE 8080 or EXPOSE 8080/udp
WORKDIR Work list If the working directory inside the specified container is not created, it will be created automatically. If the specified / uses an absolute address, if it does not start with /, then it is the relative path of the path of the previous workdir
USER Specify the execution user Specify the user when the user executes the RUN CMD ENTRYPONT when building or starting
HEALTHCHECK health examination The command to specify the health monitoring of the current container is basically useless because many times the application itself has a health monitoring mechanism
ONBUILD trigger When the image with the ONBUILD keyword is used as the base image, the ONBUILD command will be executed after the execution of FROM is completed, but it does not affect the use of the current image and is not very useful
STOPSIGNAL Send a semaphore to the host The STOPSIGNAL directive sets the system call signal that will be sent to the container to exit.
SHELL Specify the shell to execute the script Specify the shell used when RUN CMD ENTRYPOINT executes the command

3. Dockerfile deploys the springboot project

1. Prepare a simple springboot project
springboot2. Perform related operations in the cloud server

Cloud Server

dockerfile

FROM java:8
MAINTAINER henrik <10791894@qq.com>
ADD hellodocker-0.0.1-SNAPSHOT.jar app.jar
CMD java -jar app.jar

3. Execute the build command

docker build -f ./springboot_dockerfile -t app .

bulid4. Run

docker run -id -p 9000:8080 app

insert image description here

Guess you like

Origin blog.csdn.net/qq_50216270/article/details/121048474