decker常用命令(1)

decker常用命令(1)
docker search 搜索镜像
docker pull安装镜像
docker images查看镜像信息
docker tag 创建新标签
docker inspect 命令可以获取该镜像的详细信息
docker rmi 删除本地镜像文件

docker  search 搜索镜像
[root@docker ~]# docker  search busybox
NAME                      DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
busybox                   Busybox base image.                             1919                [OK]                
progrium/busybox                                                          71                                      [OK]
..............................                                                                          
joeshaw/busybox-nonroot   Busybox container with non-root user nobody     2                                       
                                    
docker pull安装镜像,可以指定特定版本
[root@docker ~]# docker pull joeshaw/busybox-nonroot

docker  images查看镜像信息
[root@docker ~]# docker  images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
busybox             latest              1c35c4412082        13 days ago         1.22MB
hello-world         latest              bf756fb1ae65        5 months ago        13.3kB

TAG----版本下载时没指定TAG的话就是下载latest最新的版本
IMAGE ID --镜像ID是十六进制的按照二进制进行显示
CREATED --被创建日期


docker  tag 创建新标签,为了方便工作,还可以使用docker tag命令为本地镜像添加新的标签,有时候镜像名称太长可以用这个方便管理,类似Linux的硬链接
[root@docker ~]# docker  tag hello-world:latest hw:latest
[root@docker ~]# docker  images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
busybox             latest              1c35c4412082        13 days ago         1.22MB
hello-world         latest              bf756fb1ae65        5 months ago        13.3kB
hw                  latest              bf756fb1ae65        5 months ago        13.3kB



docker inspect 命令可以获取该镜像的详细信息
[root@docker ~]# docker  inspect --help

Usage:  docker inspect [OPTIONS] NAME|ID [NAME|ID...]  ----加镜像名称或者ID

Return low-level information on Docker objects  ---对象指的是容器和镜像

Options:
  -f, --format string   Format the output using the given Go template
  -s, --size            Display total file sizes if the type is container
      --type string     Return JSON for specified type
	  
[root@docker ~]# docker  images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
busybox             latest              1c35c4412082        13 days ago         1.22MB
hello-world         latest              bf756fb1ae65        5 months ago        13.3kB
hw                  latest              bf756fb1ae65        5 months ago        13.3kB

输出的结果里面的数据全是键值对,整个{}中的内容是一段完整的内容
[root@docker ~]#  docker  inspect  1c35
[
    {
        "Id": "sha256:1c35c441208254cb7c3844ba95a96485388cef9ccc0646d562c7fc026e04c807",  ----镜像ID的真实数字没实际意义
        "RepoTags": [
            "busybox:latest"
        ],
        "RepoDigests": [
            "busybox@sha256:95cf004f559831017cdf4628aaf1bb30133677be8702a8c5f2994629f637a209" ---仓库的编号
        ],
        "Parent": "",
        "Comment": "",
        "Created": "2020-06-02T21:19:57.279412246Z",                                         ----创建时间
        "Container": "1c17e9df8a65c5e8e204d6a8b6131992cbbf53ccf8ded24b8b8f22efed98f2ff",     ----容器ID,容器比镜像多一个可写层
        "ContainerConfig": {
            "Hostname": "1c17e9df8a65",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
            ],
            "Cmd": [
                "/bin/sh",
                "-c",
                "#(nop) ",
                "CMD [\"sh\"]"
            ],
            "ArgsEscaped": true,
            "Image": "sha256:2aabc920ad7c34b4f1938797fd9c0b79e50820dffeeab14767ee742e441fb0b7",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": {}
        },
        "DockerVersion": "18.09.7",
        "Author": "",
        "Config": {
            "Hostname": "",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
            ],
            "Cmd": [
                "sh"
            ],
            "ArgsEscaped": true,
            "Image": "sha256:2aabc920ad7c34b4f1938797fd9c0b79e50820dffeeab14767ee742e441fb0b7",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": null
        },
        "Architecture": "amd64",          --------amd64和x86_64是一样的
        "Os": "linux",
        "Size": 1219430,
        "VirtualSize": 1219430,
        "GraphDriver": {                    ----图形驱动这里是没有
            "Data": {
                "MergedDir": "/var/lib/docker/overlay2/c3be13b599e4f5a5294298a65237412b5fd2f4af10e6410c16736986e2e66d6c/merged",
                "UpperDir": "/var/lib/docker/overlay2/c3be13b599e4f5a5294298a65237412b5fd2f4af10e6410c16736986e2e66d6c/diff",
                "WorkDir": "/var/lib/docker/overlay2/c3be13b599e4f5a5294298a65237412b5fd2f4af10e6410c16736986e2e66d6c/work"
            },
            "Name": "overlay2"
        },
        "RootFS": {
            "Type": "layers",
            "Layers": [
                "sha256:1be74353c3d0fd55fb5638a52953e6f1bc441e5b1710921db9ec2aa202725569"
            ]
        },
        "Metadata": {
            "LastTagTime": "0001-01-01T00:00:00Z"
        }
    }
]

 docker  inspect  -f用go的格式取想要的数据,
[root@docker ~]#  docker  inspect  -f "{{.ContainerConfig}}"  busybox
{1c17e9df8a65   false false false map[] false false false [PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin] [/bin/sh -c #(nop)  CMD ["sh"]] <nil> true sha256:2aabc920ad7c34b4f1938797fd9c0b79e50820dff


docker rmi  删除本地镜像文件

[root@docker ~]# docker rmi --help

Usage:  docker rmi [OPTIONS] IMAGE [IMAGE...]

Remove one or more images

Options:
  -f, --force      Force removal of the image
      --no-prune   Do not delete untagged parents
	  
[root@docker ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
busybox             latest              1c35c4412082        13 days ago         1.22MB
hello-world         latest              bf756fb1ae65        5 months ago        13.3kB
hw                  latest              bf756fb1ae65        5 months ago        13.3kB
[root@docker ~]# 
[root@docker ~]# 
[root@docker ~]# docker rmi    hw   
Untagged: hw:latest----  这里说明只是取消了标签
[root@docker ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
busybox             latest              1c35c4412082        13 days ago         1.22MB
hello-world         latest              bf756fb1ae65        5 months ago        13.3kB

这里报错 是因为容器正在指向hello-world正在运行中
[root@docker ~]# docker rmi    hello-world 
Error response from daemon: conflict: unable to remove repository reference "hello-world" (must force) - container 5a4b5c7bc36e is using its referenced image bf756fb1ae65

加f参数强制删除
[root@docker ~]# docker rmi -f   hello-world 
Untagged: hello-world:latest
Untagged: hello-world@sha256:d58e752213a51785838f9eed2b7a498ffa1cb3aa7f946dda11af39286c3db9a9
Deleted: sha256:bf756fb1ae65adf866bd8c456593cd24beb6a0a061dedf42b26a993176745f6

注意:
若删除标签,无标签指向镜像的层,则层被删除
若有其他标签执行层数据,则仅取消当前标签,而不删除层数据在这里插入代码片
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值