一:镜像
镜像是docker里面三个重要之一的东西,里面是创建容器的只读模版,就像是一个独立的软件包,就是运行某个程序必备的代码即可;传统的镜像就是包括了整个操作系统副本以及预安装的应用软件
镜像的拉取:
#默认是拉取最新的镜像 [root@qcy /]# docker pull ubuntu Using default tag: latest latest: Pulling from library/ubuntu bccd10f490ab: Pull complete Digest: sha256:77906da86b60585ce12215807090eb327e7386c8fafb5402369e421f44eff17e Status: Downloaded newer image for ubuntu:latest docker.io/library/ubuntu:latest #拉取指定版本的镜像 [root@qcy /]# docker pull ubuntu:14.04 14.04: Pulling from library/ubuntu 2e6e20c8e2e6: Pull complete 0551a797c01d: Pull complete 512123a864da: Pull complete Digest: sha256:64483f3496c1373bfd55348e88694d1c4d0c9b660dee6bfef5e12f43b9933b30 Status: Downloaded newer image for ubuntu:14.04 docker.io/library/ubuntu:14.04
二:镜像的查看
1、镜像查看实例
1:查看镜像id等
#查看帮助文档 docker images -h [root@qcy /]# docker images -h Flag shorthand -h has been deprecated, please use --help Usage: docker images [OPTIONS] [REPOSITORY[:TAG]] List images Aliases: docker image ls, docker image list, docker 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 Format output using a custom template: 'table': Print output in table format with column headers (default) 'table TEMPLATE': Print output in table format using the given Go template 'json': Print in JSON format 'TEMPLATE': Print output using the given Go template. Refer to https://docs.docker.com/go/formatting/ for more information about formatting output with templates --no-trunc Don't truncate output -q, --quiet Only show image IDs #查看本地主机上面的镜像 [root@qcy /]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE ubuntu latest ca2b0f26964c 13 days ago 77.9MB ubuntu 14.04 13b66b487594 2 years ago 197MB #查看本地某个镜像 #加上--no-trunc显示完整镜像id,就是由摘要值通过哈希函数sha256对镜像的配置文件计算得来的 [root@qcy /]# docker images ubuntu --no-trunc REPOSITORY TAG IMAGE ID CREATED SIZE ubuntu latest sha256:ca2b0f26964cf2e80ba3e084d5983dab293fdb87485dc6445f3f7bbfc89d7459 13 days ago 77.9MB ubuntu 14.04 sha256:13b66b487594a1f2b75396013bc05d29d9f527852d96c5577cc4f187559875d0 2 years ago 197MB #--digests可以显示镜像摘要值 [root@qcy /]# docker images ubuntu --digests REPOSITORY TAG DIGEST IMAGE ID CREATED SIZE ubuntu latest sha256:77906da86b60585ce12215807090eb327e7386c8fafb5402369e421f44eff17e ca2b0f26964c 13 days ago 77.9MB ubuntu 14.04 sha256:64483f3496c1373bfd55348e88694d1c4d0c9b660dee6bfef5e12f43b9933b30 13b66b487594 2 years ago 197MB #同时输出摘要值和完整的镜像id [root@qcy /]# docker images --no-trunc --digests REPOSITORY TAG DIGEST IMAGE ID CREATED SIZE ubuntu latest sha256:77906da86b60585ce12215807090eb327e7386c8fafb5402369e421f44eff17e sha256:ca2b0f26964cf2e80ba3e084d5983dab293fdb87485dc6445f3f7bbfc89d7459 13 days ago 77.9MB ubuntu 14.04 sha256:64483f3496c1373bfd55348e88694d1c4d0c9b660dee6bfef5e12f43b9933b30 sha256:13b66b487594a1f2b75396013bc05d29d9f527852d96c5577cc4f187559875d0 2 years ago 197MB
2:根据自定义输出(--format)
#输出json格式 #就是输出完整镜像的详细信息 N/A就是没有这些镜像上没有运行的容器 [root@qcy /]# docker images --format json {"Containers":"N/A","CreatedAt":"2024-02-28 02:52:59 +0800 CST","CreatedSince":"13 days ago","Digest":"\u003cnone\u003e","ID":"ca2b0f26964c","Repository":"ubuntu","SharedSize":"N/A","Size":"77.9MB","Tag":"latest","UniqueSize":"N/A","VirtualSize":"77.86MB"} {"Containers":"N/A","CreatedAt":"2021-03-26 06:33:44 +0800 CST","CreatedSince":"2 years ago","Digest":"\u003cnone\u003e","ID":"13b66b487594","Repository":"ubuntu","SharedSize":"N/A","Size":"197MB","Tag":"14.04","UniqueSize":"N/A","VirtualSize":"196.5MB"} #输入镜像名称和标签,注意格式{{}}:{{}} [root@qcy /]# docker images --format "{{.Repository}}:{{.Tag}}" ubuntu:latest ubuntu:14.04
3:只显示镜像id,方便批量对其进行操作
[root@qcy /]# docker images -q ca2b0f26964c 13b66b487594
4:镜像条件筛选(--filter)
悬挂镜像和非悬挂镜像
#dangling:显示标记为空的镜像,值只有true和false #true:就是查看悬挂的镜像,输出为空,悬挂的镜像就是不在被任何容器所引用,并且没有标签, #false:就是查看非悬挂的镜像,有输出,非悬挂的镜像就是有一个或者多个的镜像,并且可能被容器所使用 [root@qcy /]# docker images --filter dangling=true REPOSITORY TAG IMAGE ID CREATED SIZE [root@qcy /]# docker images --filter dangling=false REPOSITORY TAG IMAGE ID CREATED SIZE ubuntu latest ca2b0f26964c 13 days ago 77.9MB ubuntu 14.04 13b66b487594 2 years ago 197MB #删除悬挂的镜像(就是没有用的镜像) [root@qcy /]# docker images rmi $(docker images --filter dangling=true -q) REPOSITORY TAG IMAGE ID CREATED SIZE #before,根据时间来定义,某个镜像构建时间之前的镜像列表 [root@qcy /]# docker images --filter before=ca2b0f26964c REPOSITORY TAG IMAGE ID CREATED SIZE ubuntu 14.04 13b66b487594 2 years ago 197MB #since,匹配某个镜像之后创建的镜像 [root@qcy /]# docker images --filter since=13b66b487594 REPOSITORY TAG IMAGE ID CREATED SIZE ubuntu latest ca2b0f26964c 13 days ago 77.9MB #reference,这个是添加正则进行匹配 [root@qcy /]# docker images --filter reference=ubuntu REPOSITORY TAG IMAGE ID CREATED SIZE ubuntu latest ca2b0f26964c 13 days ago 77.9MB ubuntu 14.04 13b66b487594 2 years ago 197MB #label,根据标签进行过滤,其中label的值,是在docker在编译的时候配置的或者在dockerfile中配置的 #编辑dockerfile里的文件 [root@qcy docker-hello]# cat dockerfile FROM scratch COPY hello / LABEL version="1.0" name=qcy CMD ["/hello"] #基于dockerfile创建新的镜像 [root@qcy docker-hello]# docker build -t hello-label2 /root/docker-hello/ [root@qcy docker-hello]# docker build -t hello-label3 /root/docker-hello/ #根据镜像仓库名字进行筛选 [root@qcy docker-hello]# docker images --filter label=name REPOSITORY TAG IMAGE ID CREATED SIZE hello-label2 latest 29f3a6110d07 4 days ago 861kB hello-label3 latest 29f3a6110d07 4 days ago 861kB
2:镜像标识
镜像可以通过镜像id,镜像名称(有标签),镜像的摘要值来标识和引用
标签:--,ubuntu,images,镜像,docker,操作,root From: https://www.cnblogs.com/qm77/p/18067056