首页 > 其他分享 >docker镜像的操作

docker镜像的操作

时间:2024-03-12 10:11:41浏览次数:20  
标签:-- ubuntu images 镜像 docker 操作 root

一:镜像

镜像是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

相关文章

  • 常用的Docker命令及其用途简述
    记录常用的Docker命令及其用途在日常的开发和运维工作中,Docker和docker-compose已经成为了不可或缺的工具。它们帮助我们轻松地构建、运行和管理容器化的应用程序。在这篇随笔中,我将记录下一些我常用的Docker和docker-compose命令,并简述它们的用途,并在每一个命令后面加上一条示例......
  • 包含Maven和Docker的Dockerfile
    要创建一个包含Maven和Docker的Dockerfile,你需要首先明确你的需求。通常,这样的Dockerfile可能是为了构建并打包一个Java项目,然后使用Docker将其部署。以下是一个简单的示例,展示了如何创建一个Dockerfile,该Dockerfile安装了Maven和Docker,然后构建并推送一个Java项目:Dockerfile#......
  • Docker compose部署Typecho博客系统
    编辑docker-compose.yml文件:services:typecho:image:joyqi/typecho:nightly-php8.2-apacherestart:alwaysports:-8086:80#端口映射,把博客默认的80端口映射到8086端口environment: TYPECHO_DB_HOST:typecho_db#默认值是localhost,docker......
  • 部署测试平台-使用docker安装mysql
    1.拉取mysql5.7镜像:dockerpullmysql:5.72.新建数据库挂载目录:mkdir-p/root/data/mysql5.7/conf   配置文件mkdir-p/root/data/mysql5.7/data   数据库数据目录mkdir-p/root/data/mysql5.7/log   数据库日志3.把配置文件my.cnf放到/root/data/m......
  • PXE批量安装操作系统自动化
    PXEz自动化在PXE服务器操作:*yum-yinstalldhcpxinetdtftptftp-server**yum-yinstallsystem-config-kickstart**yum-yinstallsyslinux**[root@localhostks]#cat/etc/dhcp/dhcpd.conf**subnet192.168.7.0netmask255.255.255.0{**range192.168.7.100192.1......
  • docker部署单机版elasticsearch7
    拉取镜像dockerpulldocker.elastic.co/elasticsearch/elasticsearch:7.17.18创建本地数据、配置文件夹,修改权限sudomkdir-p/server/es7/config/server/es7/data/server/es7/logs/server/es7/pluginssudochmod777/server/es7/config/server/es7/data/server/es7/......
  • 6.Python操作数据库
    1.操作mysql数据库importpymysql#连接数据库conn=pymysql.connect(host="127.0.0.1",port=3306,user="root",password="123456",database="a",autocommit=True)#创建游标进行数据库操作以及获取数据cursor=conn.cursor(cursor=pymysql.cursors.DictCu......
  • 测试平台服务器安装docker
    1.安装docker:1.1.卸载旧版(如果没有可以跳过次步骤)sudoyumremovedocker\docker-client\docker-client-latest\docker-common\docker-latest\docker-latest-logrotate\docker-logrotate\docker-selinux\docker-engine-selinux\......
  • docker安装awvs
    1,下载awvsdockerpullsecfa/docker-awvs2,创建容器命令:dockerrun-it-d-p3443:3443secfa/docker-awvs如果报错!(提示crack失败)添加参数--cap-addLINUX_IMMUTABLE命令:dockerrun-itd-p3443:3443--cap-addLINUX_IMMUTABLE--nameawvssecfa/docker-awvs3,登录访......
  • flowable的查询操作和删除操作
    效果图 pom文件<?xmlversion="1.0"encoding="UTF-8"?><projectxmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http......