Image Management



Syntax: docker build [OPTIONS] PATH | URL | -

Function: Builds an image using the Dockerfile in the specified path.

Parameters: Common parameters are as follows. For details about more parameters, run the docker help build command.

Table 4 Parameter description




Deletes containers generated during the build process even if the build is not successful.


Builds the image without using cache.

-q, --quiet=false

Suppresses the redundant information generated during the the build process.


Deletes the container generated during the build after the build is successful.

-t, --tag=""

Specifies the tag name of the image generated during the build.


Configures the build parameters.


Image-related parameters. The description of each parameter is similar to that of the create command.


Specifies the container isolation method.


Always attempts to obtain the latest version of the image during the build process.

Dockerfile Description

Dockerfile is used to automatically build a container by describing how to build an image. All Dockerfile instructions are in the INSTRUCTION arguments format.


FROM Instruction

Syntax: FROM <image> or FROM <image>:<tag>

Function: Specifies a base image, which is the first instruction in all Dockerfiles. If the tag of the base image is not specified, the default tag name latest is used.


RUN Instruction

Syntax: RUN <command> (The shell form. The command is run in a shell which by default is /bin/sh -c) or

RUN ["<executable>", “<param1>”, “<param2>” … ] (The exec form)

Function: Executes any commands in the image specified by the FROM instruction and then commits the result. The committed image will be used in the next step in the Dockerfile. The RUN instruction is equivalent to:

docker run <image> <command>

docker commit <container_id>



The number sign (#) is used to comment out.


MAINTAINER Instruction

Syntax: MAINTAINER <name>

Function: Specifies the name and contact information of the maintainer.


ENTRYPOINT Instruction

Syntax: ENTRYPOINT <cmd> <param1> <param2>… or ENTRYPOINT ["<cmd>", “<param1>”, “<param2>”…]

Function: Configures the commands to be executed during container startup.


USER Instruction

Syntax: USER <name>

Function: Specifies the user to run memcached.


EXPOSE Instruction

Syntax: EXPOSE <port> [<port>…]

Function: Exposes one or more ports of the image.


ENV Instruction

Syntax: ENV <key> <value>

Function: Configures environment variables. The configured environment variables can be used by the subsequent RUN instructions.


ADD Instruction

Syntax: ADD <src> <dst>

Function: Copies a file from <src> directory to <dest> directory of the container. <src> is a relative path of the source directory to be built. It can be the path of a file or directory, or a remote file URL. <dest> is an absolute path of the container.


VOLUME Instruction

Syntax: VOLUME ["<mountpoint>"]

Function: Creates a mount point for the shared directory.


WORKDIR Instruction

Syntax: WORKDIR <path>

Function: Sets the working path for the RUN, CMD, and ENTRYPOINT instructions. The working path can be set multiple times. If the working path is a relative path, it is relative to the previous WORKDIR instruction.


CMD Instruction

Syntax: CMD ["<executable>","<param1>","<param2>"] (The exec form. This is the preferred form.)

CMD ["<param1>","<param2>"] (The arguments are the default arguments for ENTRYPOINT.)

CMD “<command>” “<param1>” “<param2>” (The shell form.)

Function: A Dockerfile can contain only one CMD instruction. If there are multiple CMD instructions, only the last one takes effect.


ONBUILD Instruction

Syntax: ONBUILD [other instructions]

Function: This instruction is followed by other instructions, such as the RUN and COPY instructions. This instruction is not executed during image build and is executed only when the current image is used as the base image for another build.

The following is a complete example of a Dockerfile that builds an image with the sshd service installed.

FROM busybox
ENV  http_proxy
ENV  https_proxy
RUN apt-get update && apt-get install -y openssh-server
RUN mkdir -p /var/run/sshd
ENTRYPOINT /usr/sbin/sshd -D

Example commands:

  1. Run the following command to build an image using the preceding Dockerfile:

    $ sudo docker build -t busybox:latest
  2. Run the following command to view the generated image:

    docker images | grep busybox


Syntax: docker history [OPTIONS] <IMAGE>

Function: Displays the change history of an image.


-H, –human=true

–no-trunc=false: Indicates that the output is not truncated.

-q and –quiet=false: Displays IDs only.


$ sudo docker history busybox:test
IMAGE               CREATED             CREATED BY          SIZE                COMMENT
be4672959e8b        15 minutes ago      bash                23B
21970dfada48        4 weeks ago                             128MB               Imported from -



Syntax: docker images [OPTIONS] [NAME]

Function: Lists existing images. The intermediate images are not displayed if no parameter is added.


-a and –all=false: Displays all images.

-f and –filter=[]: Specifies a filter, for example, dangling=true.

–no-trunc=false: Indicates that the output is not truncated.

-q and –quiet=false: Displays IDs only.


$ sudo docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
busybox             latest              e02e811dd08f        2 years ago         1.09MB



Syntax: docker import URL|- [REPOSITORY[:TAG]]

Function: Imports a .tar package that contains a rootfs as an image. This parameter corresponds to the docker export command.

Parameters: none.


Run the following command to generate a new image from the busybox.tar file exported using the docker export command:

$ sudo docker import busybox.tar busybox:test
$ sudo docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
busybox             test                a79d8ae12403        2 seconds ago       1.3MB



Syntax: docker load [OPTIONS]

Function: Loads an image from .tar package obtained using the docker save command. This command corresponds to the docker save command.


-i and –input="".


$ sudo docker load -i busybox.tar
Loaded image ID: sha256:e02e811dd08fd49e7f6032625495118e63f597eb150403d02e3238af1df240ba
$ sudo docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
busybox             latest              e02e811dd08f        2 years ago         1.09MB


Syntax: docker login [OPTIONS] [SERVER]

Function: Logs in to an image registry. If no server is specified, the system logs in to by default.


-e and –email="": Email address.

-p and –password="": Password.

-u and –username="": User name.


$ sudo docker login


Syntax: docker logout [SERVER]

Function: Logs out from an image registry. If no server is specified, the system logs out from by default.

Parameters: none.


$ sudo docker logout


Syntax: docker pull [OPTIONS] NAME[:TAG]

Function: Pulls an image from the official or private registry.


-a and –all-tags=false: Downloads all images in the registry. (A registry can be tagged with multiple tags. For example, a BusyBox registry may have multiple tags, such as busybox:14.04, busybox:13.10, busybox:latest. If -a is used, all BusyBox images with tags are pulled.)


  1. Run the following command to pull an Nginx image from the official registry:

    $ sudo docker pull nginx
    Using default tag: latest
    latest: Pulling from official/nginx
    94ed0c431eb5: Pull complete
    9406c100a1c3: Pull complete
    aa74daafd50c: Pull complete
    Digest: sha256:788fa27763db6d69ad3444e8ba72f947df9e7e163bad7c1f5614f8fd27a311c3
    Status: Downloaded newer image for nginx:latest

    When pulling the image, the system checks whether the dependent layer exists. If yes, the local layer is used.

  2. Pull an image from a private registry.

    Run the following command to pull a Fedora image from the private registry, assuming the address of the private registry is

    $ sudo docker pull


Syntax: docker push NAME[:TAG]

Function: Pushes an image to the image registry.

Parameters: none.


  1. Assume an image is to be push to the private image registry at

  2. Label the image to be pushed. (The docker tag command is described in the following section.) In this example, the image to be pushed is busybox:sshd.

    $ sudo docker tag ubuntu:sshd
  3. Run the following command to push the tagged image to the private image registry:

    $ sudo docker push

    During the push, the system automatically checks whether the dependent layer exists in the image registry. If yes, the layer is skipped.


Syntax: docker rmi [OPTIONS] IMAGE [IMAGE…]

Function: Deletes one or more images. If an image has multiple tags in the image library, the image is not deleted but only untagged. When an image with one tag is deleted, the dependent layers are deleted in sequence.


-f and –force=false: Forcibly deletes the images.

–no-prune=false: Does not delete parent images without tags.


$ sudo docker rmi


Syntax: docker save [OPTIONS] IMAGE [IMAGE…]

Function: Saves an image to a .tar package. The results are output to STDOUT by default.


-o and –output="": Outputs the results to a file rather than STDOUT.


$ sudo docker save -o nginx.tar nginx:latest
$ ls

Syntax: docker search [OPTIONS] TERM

Function: Searches for specific images in the image registry.


–automated=false: Displays the automatically built image.

–no-trunc=false: Indicates that output is not truncated.

-s and –stars=0: Displays only images that have a specific number of stars or more.


  1. Run the following command to search for Nginx images in the official image library:

    $ sudo docker search nginx
    NAME                              DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
    nginx                             Official build of Nginx.                        11873               [OK]
    jwilder/nginx-proxy               Automated Nginx reverse proxy for docker con...   1645                                    [OK]
    richarvey/nginx-php-fpm           Container running Nginx + PHP-FPM capable of...   739                                     [OK]
    linuxserver/nginx                 An Nginx container, brought to you by LinuxS...   74
    bitnami/nginx                     Bitnami nginx Docker Image                      70                                      [OK]
    tiangolo/nginx-rtmp               Docker image with Nginx using the nginx-rtmp...   51                                      [OK]


  2. Run the following command to search for BusyBox images in the private image library. Add the address to search the private image library.

    $ sudo docker search



Function: Tags an image into a registry.


-f or –force=false: Forcibly replaces the original image when the tag names are the same.


$ sudo docker tag busybox:latest busybox:test




提交类型 issue

● 错别字或拼写错误;标点符号使用错误;

● 链接错误、空单元格、格式错误;

● 英文中包含中文字符;

● 界面和描述不一致,但不影响操作;

● 表述不通顺,但不影响理解;

● 版本号不匹配:如软件包名称、界面版本号;


● 关键步骤错误或缺失,无法指导用户完成任务;

● 缺少必要的前提条件、注意事项等;

● 图形、表格、文字等晦涩难懂;

● 逻辑不清晰,该分类、分项、分步骤的没有给出;


● 技术原理、功能、规格等描述和软件不一致,存在错误;

● 原理图、架构图等存在错误;

● 命令、命令参数等错误;

● 代码片段错误;

● 命令无法完成对应功能;

● 界面错误,无法指导操作;


● 对重要数据或系统存在风险的操作,缺少安全提示;


● 违反法律法规,涉及政治、领土主权等敏感词;

● 内容侵权;