Docker image common commands explained

The installation and deployment of Docker was introduced earlier, and a Hello Word image was pulled and run from the mirror warehouse. In this article, we mainly introduce the common commands related to Docker mirroring, mirror warehouse and mirror operation. First, let's take a look at the common commands of the mirror warehouse: login, logout, pull, push, search. The command details are as shown:

docker login

The docker login command is used to log in to a Docker mirror warehouse. If the mirror warehouse address is not specified, the default login warehouse address is: the official warehouse Docker Hub. The following is the usage and description of the docker login command:

docker login [OPTIONS] [SERVER] Commonly used OPTIONS parameters are -u for the user name, -p login password, SERVER for the mirror address to log in, the following is an example of docker login:

docker login -u 用户名 -p 密码

docker logout

The docker logout command logs out a Docker mirror warehouse. If the mirror warehouse address is not specified, the official warehouse Docker Hub is the default. The following is the syntax and usage of docker logout:

docker logout [OPTIONS] [SERVER]
docker logout

docker pull

This command has been used before, and it is used to pull or update the specified mirror from the mirror warehouse. We use this command to pull a Hello Word image from the mirror website. The following is the syntax format of docker pull:

docker pull [OPTIONS] NAME[:TAG|@DIGEST]

The above OPTIONS parameters are -a: pull all tagged mirrors; --disable-content-trust: ignore mirror verification, which is enabled by default. Among them, TAG can be used to specify the mirror version. If TAG is not specified, the mirror with the latest TAG will be pulled by default. The following is an example of docker pull:

docker pull java    #下载最新的java镜像

docker push

Compared with docker pull, the docker push command is used to upload the local image to the mirror warehouse, and you need to use the docker login command to log in to the docker warehouse before using this command. The following is the syntax format of docker push:

docker push [OPTIONS] NAME[:TAG]

The OPTIONS commonly used parameter in the above command syntax is mainly --disable-content-trust, which means that the verification of the image is ignored, and the default is on. The following is an example of docker push, which pushes the v1 version of myapache image to the docker warehouse.

docker push myapache:v1

docker search

docker search: The command is used to find images from the Docker Hub repository. We can find and use the most to get the image, and then pull the image file. The following is the command format of docker search:

docker search [OPTIONS] TERM

Commonly used OPTIONS parameters are --automated: only list the mirrors of the automated build type; --no-trunc: display the complete mirror description; -s: list the mirrors whose number of favorites is not less than the specified value. The following is an example of the docker search command. The mirror parameters listed are NAME: the name of the mirror repository source; DESCRIPTION: the description of the mirror; OFFICIAL: whether it is officially released by docker; stars: similar to the stars in Github, which means likes and likes Meaning; AUTOMATED: Automatic construction.

docker search -s 10 java
NAME                  DESCRIPTION                           STARS   OFFICIAL   AUTOMATED
java                  Java is a concurrent, class-based...   1037    [OK]       
anapsix/alpine-java   Oracle Java 8 (and 7) with GLIBC ...   115                [OK]
develar/java                                                 46                 [OK]
isuper/java-oracle    This repository contains all java...   38                 [OK]
lwieske/java-8        Oracle Java 8 Container - Full + ...   27                 [OK]
nimmis/java-centos    This is docker images of CentOS 7...   13                 [OK]

docker images

Docker images is used to list local images, and its format is docker images [OPTIONS] [REPOSITORY[:TAG]]. OPTIONS has the following parameters: -a: List all local mirrors (including the intermediate image layer, by default, filter out the intermediate image layer); --digests: display the summary information of the mirror; -f: display the mirrors that meet the conditions ; --Format: Specify the template file of the return value; --no-trunc: display the complete mirror information; -q: only display the mirror ID. The following is an example of docker images:

docker images

docker rmi

Docker rmi is used to delete one or how many local mirrors. The syntax is docker rmi [OPTIONS] IMAGE [IMAGE...]. Among them, OPTIONS includes: -f: force deletion; --no-prune: do not remove the process image of the image, it is removed by default; the following is an example used by docker rmi:

docker rmi -f ubuntu:v4

docker tag

The Docker tag command is used to mark local images and put them into a certain warehouse. The syntax format is: docker tag [OPTIONS] IMAGE[:TAG] [REGISTRYHOST/][USERNAME/]NAME[:TAG], the following is an example of use:

docker tag ubuntu:15.10 microservice/ubuntu:v3

docker history

The docker history command is used to view the creation history of the specified image. The syntax is docker history [OPTIONS] IMAGE, OPTIONS has: -H: print the image size and date in a readable format, the default is true; --no-trunc: display the complete submission record; -q: list only the submissions Record ID. The following is an example of the use of docker history:

docker history microservice/ubuntu:v3

docker save

docker save is used to save the specified image as a tar archive file. The syntax is docker save [OPTIONS] IMAGE [IMAGE...]. OPTIONS has the parameter -o to indicate the output file.

docker save -o my_ubuntu_v3.tar microservice/ubuntu:v3

docker load

docker load is used to import the image exported using the docker save command. The command format is: docker load [OPTIONS]. OPTIONS parameters are: --input, -i: specify the imported file instead of STDIN. --quiet, -q: streamline the output information.

docker load --input fedora.tar

docker import

docker import is used to create images from archive files. The syntax is: docker import [OPTIONS] file|URL|- [REPOSITORY[:TAG]] OPTIONS parameters are: -c: use the docker command to create a mirror; -m: the description text when submitting.

docker import  my_ubuntu_v3.tar microservice/ubuntu:v4

docker build

The docker build command is used to create an image using Dockerfile. No more detailed description here, the command format is docker build [OPTIONS] PATH | URL | -. The OPTIONS parameter has the following parameters:
 

--build-arg=[] :设置镜像创建时的变量;
--cpu-shares :设置 cpu 使用权重;
--cpu-period :限制 CPU CFS周期;
--cpu-quota :限制 CPU CFS配额;
--cpuset-cpus :指定使用的CPU id;
--cpuset-mems :指定使用的内存 id;
--disable-content-trust :忽略校验,默认开启;
-f :指定要使用的Dockerfile路径;
--force-rm :设置镜像过程中删除中间容器;
--isolation :使用容器隔离技术;
--label=[] :设置镜像使用的元数据;
-m :设置内存最大值;
--memory-swap :设置Swap的最大值为内存+swap,"-1"表示不限swap;
--no-cache :创建镜像的过程不使用缓存;
--pull :尝试去更新镜像的新版本;
--quiet, -q :安静模式,成功后只输出镜像 ID;
--rm :设置镜像成功后删除中间容器;
--shm-size :设置/dev/shm的大小,默认值是64M;
--ulimit :Ulimit配置。
--tag, -t: 镜像的名字及标签,通常 name:tag 或者 name 格式;可以在一次构建中为一个镜像设置多个标签。
--network: 默认 default。在构建期间设置RUN指令的网络模式

The use of the docker build command will not be introduced here. When we introduce the Dockfile later, we will introduce the use of docker build in detail. Here is a simple docker build example:

docker build -t microservice/ubuntu:v1 . 

 

Guess you like

Origin blog.csdn.net/wk19920726/article/details/108581257