| 一、查看镜像有关信息1.1 查看镜像历史分层root@lck:~
root@lck:~
IMAGE               CREATED             CREATED BY                                      SIZE                COMMENT
ae2feff98a0c        2 weeks ago         /bin/sh -c 
<missing>           2 weeks ago         /bin/sh -c 
<missing>           2 weeks ago         /bin/sh -c 
<missing>           2 weeks ago         /bin/sh -c 
<missing>           2 weeks ago         /bin/sh -c 
<missing>           2 weeks ago         /bin/sh -c 
<missing>           2 weeks ago         /bin/sh -c 
<missing>           2 weeks ago         /bin/sh -c set -x     && addgroup --system -…   63.7MB              
<missing>           2 weeks ago         /bin/sh -c 
<missing>           2 weeks ago         /bin/sh -c 
<missing>           2 weeks ago         /bin/sh -c 
<missing>           3 weeks ago         /bin/sh -c 
<missing>           3 weeks ago         /bin/sh -c 
<missing>           3 weeks ago         /bin/sh -c 
 1.2 获取镜像元数据(JOSN格式)root@lck:~
 1.3 将指定镜像保存成 tar 归档文件docker save -o nginx nginx.tar
[root@ubuntu1804 ~]
-rw------- 1 root root 131M Jul 20 22:33 nginx.tar
 二、搜索镜像格式 docker search [OPTIONS] TERM
Options:
-f, --filter filter   Filter output based on conditions provided        
     --format string   Pretty-print search using a Go template
     --limit int       Max number of search results (default 25)        
     --no-trunc       Don't truncate output                             
说明:  
OFFICIAL: 官方
AUTOMATED: 使用第三方docker服务来帮助编译镜像,可以在互联网上面直接拉取到镜像,减少了繁琐的编译过程
 2.1 搜索 centos 有关镜像root@lck:~
NAME                               DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
centos                             The official build of CentOS.                   6351                [OK]                
ansible/centos7-ansible            Ansible on Centos7                              132                                     [OK]
consol/centos-xfce-vnc             Centos container with "headless" VNC session…   124                                     [OK]
jdeathe/centos-ssh                 OpenSSH / Supervisor / EPEL/IUS/SCL Repos - …   117                                     [OK]
centos/systemd                     systemd enabled base container.                 92                                      [OK]
 2.2 搜索点赞100个以上的镜像docker search -s 100 centos               
docker search --filter=stars=100 centos   
docker search  centos -f stars=100
 2.3 搜索官方发行版本docker search  centos -f is-offical=true
 三、下载镜像格式 docker pull [OPTIONS] NAME[:TAG|@DIGEST]
Options:
-a, --all-tags               Download all tagged images in the repository
     --disable-content-trust   Skip image verification (default true)
     --platform string         Set platform if server is multi-platform capable
-q, --quiet                   Suppress verbose output
NAME: 是镜像名,一般的形式 仓库服务器:端口/项目名称/镜像名称
:TAG: 即版本号,如果不指定 :TAG 则下载最新版镜像
 3.1 镜像下载信息说明root@lck:~
Using default tag: latest                                                        
latest: Pulling from library/hello-world
0e03bdcc26d7: Pull complete                                                      
Digest: sha256:1a523af650137b8accdaed439c17d684df61ee4d74feac151b5b337bd29e7eec  
Status: Downloaded newer image for hello-world:latest                            
docker.io/library/hello-world:latest                                             
 镜像下载保存的路径 /var/lib/docker/overlay2/镜像ID
 3.2 安装指定TAG的特定版本镜像
 docker pull docker.io/library/mysql:5.7.32
docker pull mysql:5.7.32
 3.3 指定DIGEST下载特定版本的镜像先到 hub.docker.com查到指定版本的DIGEST docker pull alpine:20200626
 四、查看本地镜像格式 docker images [OPTIONS] [REPOSITORY[:TAG]]
常用选项:  
-q, --quiet     Only show numeric IDs                           
-a, --all Show all images (default hides intermediate images)   
--digests       Show digests                                    
--no-trunc     Don't truncate output                            
 4.1 执行结果信息说明root@lck:~
REPOSITORY    TAG        IMAGE ID       CREATED         SIZE
busybox       latest     a77dce18d0ec   5 days ago      1.24MB
mysql         5.7.32     f07dfa83b528   13 days ago     448MB
alpine        latest     389fef711851   2 weeks ago     5.58MB
alpine        20200626   3c791e92a856   6 months ago    5.57MB
hello-world   latest     bf756fb1ae65   12 months ago   13.3kB
REPOSITORY              
TAG                     
IMAGE ID                
CREATED                 
VIRTUAL SIZE            
 4.2 只查找指定镜像root@lck:~
REPOSITORY   TAG        IMAGE ID       CREATED        SIZE
alpine       latest     389fef711851   2 weeks ago    5.58MB
alpine       20200626   3c791e92a856   6 months ago   5.57MB
 4.3 查看指定镜像的信息root@lck:~
 五、镜像导出利用docker save命令可以将从本地镜像导出问为一个打包 tar文件,然后复制到其他服务器进行导入使用 格式 docker save [OPTIONS] IMAGE [IMAGE...]
选项:  
-o, --output string   Write to a file, instead of STDOUT
 常见用法: docker save IMAGE -o /path/file.tar
docker save IMAGE > /path/file.tar
docker save mysql:5.7.29 -o /data/mysql5.7.29.tar
docker save alpine:3.11.3 > /data/alpine.tar
 一次导出多个镜像 docker save busybox alpine > /all.tar
 六、删除镜像格式 docker rmi [OPTIONS] IMAGE [IMAGE...]
-f, --force      Force removal of the image
    --no-prune   Do not delete untagged parents
 删除镜像 docker rmi 镜像ID
docker rmi alpine:3.11.3
 删除多个镜像 docker rmi nginx tomcat
 强制删除正在使用的镜像,也会删除对应的容器 docker rmi -f centos:centos8.1.1911
 删除所有镜像 docker rmi -f `docker images -q`
 七、镜像打标签docker tag 可以给镜像打标签,类似于起别名 格式 docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]
 范例:IMAGE ID不变,只有TAG变 root@lck:/home/lck
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
alpine       latest    389fef711851   2 weeks ago   5.58MB
root@lck:/home/lck
root@lck:/home/lck
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
alpine       3.11      389fef711851   2 weeks ago   5.58MB
alpine       latest    389fef711851   2 weeks ago   5.58MB
 八、镜像导入利用docker load命令可以将镜像导出的压缩文件再导入 格式 docker load [OPTIONS]
-i, --input string   Read from tar archive file, instead of STDIN
-q, --quiet         Suppress the load output
 docker load -i /data/alpine.tar
docker load < /data/mysql5.7.29.tar.gz
 一次导出多个镜像,并导入 docker save busybox alpine > /all.tar
docker load -i /opt/all.tar
 一次导出多个镜像,并导入,导出的镜像repository、tag标记为none docker save `docker images -q` > /all.tar
docker load -i /opt/all.tar
 一次导出多个镜像,并导入,导出的镜像repository、tag标记不为空 nusybox:v1.0 docker save `docker images | awk 'NR!=1{print $1":"$2}'` > /all.tar
docker load -i /opt/all.tar
 八、阿里云镜像加速网站:http://cr.console.aliyun.com |