How does docker start from a blank image and make a base image,

To start building a base image from a blank image, follow these steps:

  1. Choose a blank mirror as a base, eg scratchmirror.
  2. Create a Dockerfile, which defines the software packages, configuration files, etc. that the base image needs to install.
  3. ADDUse the or directive in the Dockerfile COPYto add packages, configuration files, etc. to the image.
  4. Use RUNinstructions to execute commands in the image, such as installing software packages, configuring environment variables, and so on.
  5. Use CMDthe or ENTRYPOINTdirective to define the command or program to be executed by default after the container starts.
  6. Use docker buildthe command to build the Dockerfile into an image. Here is a simple example Dockerfile for building a scratchbase image based on the image:
 
 

plaintextCopy code

FROM scratch # 添加软件包和配置文件 ADD software.tar.gz / ADD config / # 执行命令 RUN apt-get update && \ apt-get install -y software-package && \ rm -rf /var/lib/apt/lists/* # 定义容器启动后默认执行的命令 CMD ["software-package"]

Build the image with docker buildthe command:

 
 

plaintextCopy code

docker build -t my-base-image .

Where my-base-imageis the name of the image, .indicating the directory where the Dockerfile is located. After the build is complete, you can use docker runthe command to start the container and execute the default command:

 
 

plaintextCopy code

docker run --rm my-base-image  

--rm 是容器运行结束后自动删除容器

Guess you like

Origin blog.csdn.net/ihateright/article/details/131169845