Docker basic common commands, docker commands, image commands

content

Docker common commands

Container help commands

 mirror command

What is mirroring? Mirroring explanation:

How to get the mirror:

Docker image loading principle: UnionFS (Union File System)

docker search [image:tag] Search for images

docker pull [image:tag] pull image 

docker pull [image:label] Pull the specified version

docker rmi [image:label] or [image id] delete image

docker rmi -f $(docker images -aq) delete all images




Docker common commands

Container help commands

docker --help        可以查看docker所有命令
docker 命令 --help 可以查看该命令的使用方式和参数

docker version    #显示docker的版本信息
docker info       #显示docker的系统信息,包括镜像和容器数量
docker 命令 --help  #帮助命令

The address of the help documentation: docker | Docker Documentation https://docs.docker.com/engine/reference/commandline/docker/

The official website help document will have commands in docker, click the corresponding command to see the usage and function of this command. 

 

 mirror command

What is mirroring? Mirroring explanation:

An image is a lightweight, executable independent software package used to package the software runtime environment and software developed based on the runtime environment. It contains all the content required to run a software, including code, runtime, libraries, and environments. variables and configuration files.

All applications, package the docker image directly, you can run it directly!

How to get the mirror:

1. Download from remote repository

2. Someone else copied it to you

3. Make an image DockerFile yourself

Docker image loading principle: UnionFS (Union File System)

When we download, we see layer by layer is this joint file system!

UnionFS (Union File System): The Union File System (UnionFS) is a layered, lightweight and high-performance file system. It supports changes to the file system as a commit to stack layer by layer. The directory is mounted under the same virtual file system, and the Union file system is the basis of the docker image. Images can be inherited through layers. Based on the base image (without parent image), various specific application images can be created.

Features: Load multiple file systems at the same time, but from the outside, only one file system can be seen. Joint loading will superimpose each layer of file systems, so that the final file system will contain all the underlying files and directories.

docker images         View all images on the local host

Example: If you will not use the docker command, or want to know what parameters the command has, you can use:

docker images --help

[root@localhost ~]# docker images --help

Usage:  docker images [OPTIONS] [REPOSITORY[:TAG]]

List images

Options:
  -a, --all             Show all images (default hides intermediate images)
      --digests         Show digests
  -f, --filter filter   Filter output based on conditions provided
      --format string   Pretty-print images using a Go template
      --no-trunc        Don't truncate output
  -q, --quiet           Only show image IDs

中文翻译:
列出图片

选项:
-a、 --全部显示所有镜像(默认隐藏中间镜像)
--摘要显示摘要
-f、 --根据提供的条件过滤输出
--使用Go模板格式化字符串打印镜像
--no trunc不截断输出
-q、 --仅显示镜像ID

其中docker images -a和-q参数比较常用,也可以-aq一起写:
-a      全部显示所有镜像
-q      仅显示镜像ID
[root@localhost ~]# docker images

REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
hello-world   latest    feb5d9fea6a5   6 months ago   13.3kB


#解释:

REPOSITORY   镜像的仓库源
TAG          镜像标签
IMAGE ID     镜像ID
CREATED      镜像的创建时间
SIZE         镜像的大小

docker search [image:tag]         Search for images

Example: Search what version of mysql image is in the docker hub library

[root@localhost ~]# docker search mysql
NAME                             DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
mysql                            MySQL is a widely used, open-source relation…   12408     [OK]
mariadb                          MariaDB Server is a high performing open sou…   4780      [OK]
mysql/mysql-server               Optimized MySQL Server Docker images. Create…   918                  [OK]


解释:

STARS          收藏,镜像的收藏人数,数字代表该镜像被收藏的数量
DESCRIPTION    镜像的描述,可以根据描述知道该镜像的功能


可选项:
--filter       过滤
使用方法;
--filter=STARS=3000     以收藏量为过滤条件,过滤出收藏量在三千以上的镜像


实操:
[root@localhost ~]# docker search mysql --filter=STARS=3000
NAME      DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
mysql     MySQL is a widely used, open-source relation…   12408     [OK]
mariadb   MariaDB Server is a high performing open sou…   4780      [OK]

过滤后只剩下收藏量在三千以上的镜像了

docker pull [image:tag]         pulls the image 

[root@localhost ~]# docker pull mysql
Using default tag: latest        #如果不写tag,默认就是latest,最新版
latest: Pulling from library/mysql
f003217c5aae: Pull complete    #分层下载,docker images 的核心,联合文件系统
65d94f01a09f: Pull complete
43d78aaa6078: Pull complete
a0f91ffbdf69: Pull complete
59ee9e07e12f: Pull complete
04d82978082c: Pull complete
70f46ebb971a: Pull complete
db6ea71d471d: Pull complete
c2920c795b25: Pull complete
26c3bdf75ff5: Pull complete
9ec1f1f78b0e: Pull complete
4607fa685ac6: Pull complete
Digest: sha256:1c75ba7716c6f73fc106dacedfdcf13f934ea8c161c8b3b3e4618bcd5fbcf195    #签名信息,防伪标志。
Status: Downloaded newer image for mysql:latest
docker.io/library/mysql:latest    #真实地址

解释:
Using default tag: latest    使用默认标签,最新的。默认下载最新版本的镜像
tag    标签
latest   最新的
docker.io/library/mysql:latest    #真实地址,等价于docker pull mysql

注:
拉取镜像也可使用真实地址,这里
docker pull mysql == docker.io/library/mysql:latest

docker pull [image:label]       pulls the specified version

The specified version download must have the version in the docker hub library

[root@localhost ~]# docker pull mysql:5.7
5.7: Pulling from library/mysql
f003217c5aae: Already exists  #已经存在
65d94f01a09f: Already exists
43d78aaa6078: Already exists
a0f91ffbdf69: Already exists
59ee9e07e12f: Already exists
04d82978082c: Already exists
70f46ebb971a: Already exists
ba61822c65c2: Pull complete
dec59acdf78a: Downloading [=====>                                             ]  12.87MB/108.6MB
0a05235a6981: Download complete
c87d621d6916: Download complete


#解释:
Already exists 已经存在

docker的核心,分层下载,将需要拉取的镜像分为多层,逐一下载。
若后续下载的其他版本的镜像有分层是一样的,就不会下载了,会显示该分层已经存在。共用这个分层,联合文件系统。

docker rmi [image:tag] or [image id]         delete image

Detailed explanation of rmi rm=removal (removal) i=images (mirror)

Optional parameters: -f force delete image docker rmi -f image

[root@localhost ~]# docker rmi mysql
Untagged: mysql:latest
Untagged: mysql@sha256:1c75ba7716c6f73fc106dacedfdcf13f934ea8c161c8b3b3e4618bcd5fbcf195
Deleted: sha256:667ee8fb158e365450fc3f09712208fe44e9f1364a9b130fed95f3f4862f8a63
Deleted: sha256:daba3b5cd1b725f259d5d59049c7011f6a20f2e7e4782b873cadeedbc1a4f122
Deleted: sha256:407a68a397de3c8e4da2ccd388f27c795519414cc9319f674e7b9a492cd8514b
Deleted: sha256:6967db79cb8031d7e505dd82c91c6426e84c6ad2098d06c1c090485886bc1c63
Deleted: sha256:3dcc0f922d11309b2e4870d5f42c5005f086c9b9c1e128ed2b712b65fa79a5c9
Deleted: sha256:ae5d4ab2734d5c27069212b2690dc2c7ac4cd85ee5e122607cb175f7fe908914
Deleted: sha256:610784bcaae50e999566928bdec7a4e146fe075d9e487bde0a228c99013ff1d9
Deleted: sha256:ccebaff04ea21a9e2df07f9d5af5c47ccd141cd3590f4d45784b6075e7c17ded
Deleted: sha256:716203221cd982fc07b80efda0c53a759ecfd69b2d93d4e8adf5fa094351372e
Deleted: sha256:fbd4939b3eb58642a07003e076acc3d0d8140797f61139ce4d3645790d9c8b51
Deleted: sha256:88f8458b4b2030b229b9757bd4061bce58b65e831a0bba8fa71aa8b3f87db630
Deleted: sha256:f2f431ab3ddc1460d300cd86016cc03b7611b56f04bd88370da3d378b3d10aea
Deleted: sha256:c1065d45b8722a4385f2ee26116e1859e8083400ee00d2beff3fdd5225bfeee9

删除镜像时也是逐一删除镜像的分层

docker rmi -f $(docker images -aq)         delete all images

[root@localhost ~]# docker rmi -f $(docker images -aq)
Untagged: hello-world:latest
Untagged: hello-world@sha256:bfea6278a0a267fad2634554f4f0c6f31981eea41c553fdf5a83e95a41d40c38
Deleted: sha256:feb5d9fea6a5e9606aa995e879d862b825965ba48de054caab5ef356dc6b3412


#解释

rmi   # remove images   移除镜像
-f    # 强制删除
$()   #传递参数,将括号里的参数传递给该命令

docker images -aq    #查看所有docker镜像的ID
-a    #查看所有
-q    #只看镜像ID

docker rmi -f $(docker images -aq)    #将所有的镜像ID传递给删除镜像这个命令,这个命令会依次执行删除。

Guess you like

Origin blog.csdn.net/weixin_53466908/article/details/124161034
Recommended