• docker镜像管理


    docker镜像管理

    镜像结构和原理

    镜像就是创建容器的模版,含有容器启动所需要的文件系统及所需要的内容,因此镜像主要用于方便和快速创建启动容器

    镜像结构:
    在这里插入图片描述

    一个典型的 Linux文件系统由 bootfs 和 rootfs 两部分组成

    bootfs(boot file system) 主要包含bootloader和kernel,bootloader主要用于引导加载 kernel,Linux

    刚启动时会加载bootfs文件系统,当boot加载完成后,kernel 被加载到内存中后接管系统的控制权,bootfs

    会被 umount 掉

    rootfs (root file system) 包含的就是典型 Linux 系统中的/dev,/proc,/bin,/etc 等标准目录和文件,

    不同的 linux 发行版(如 ubuntu 和 CentOS ) 主要在 rootfs 这一层会有所区别。

    一般的镜像通常都比较小,官方提供的Ubuntu镜像只有60MB多点,而 CentOS 基础镜像也只有200MB

    左右,一些其他版本的镜像甚至只有几MB,比如: busybox 才1.22MB,alpine镜像也只有5M左右。镜

    像直接调用宿主机的内核,镜像中只提供 rootfs,也就是只需要包括最基本的命令,配置文件和程序库等

    相关文件就可以了。

    在这里插入图片描述
    在这里插入图片描述

    查看镜像的分层结构

    [root@localhost ~]# docker pull nginx
    Using default tag: latest
    Trying to pull repository docker.io/library/nginx ...
    latest: Pulling from docker.io/library/nginx
    a603fa5e3b41: Pull complete
    c39e1cda007e: Pull complete
    90cfefba34d7: Pull complete
    a38226fb7aba: Pull complete
    62583498bae6: Pull complete
    9802a2cfdb8d: Pull complete
    Digest: sha256:e209ac2f37c70c1e0e9873a5f7231e91dcd83fdf1178d8ed36c2ec09974210ba
    Status: Downloaded newer image for docker.io/nginx:latest
    [root@localhost ~]# docker image history nginx
    IMAGE               CREATED             CREATED BY                                      SIZE                COMMENT
    88736fe82739        2 weeks ago         /bin/sh -c #(nop)  CMD ["nginx" "-g" "daem...   0 B
    <missing>           2 weeks ago         /bin/sh -c #(nop)  STOPSIGNAL SIGQUIT           0 B
    <missing>           2 weeks ago         /bin/sh -c #(nop)  EXPOSE 80                    0 B
    <missing>           2 weeks ago         /bin/sh -c #(nop)  ENTRYPOINT ["/docker-en...   0 B
    <missing>           2 weeks ago         /bin/sh -c #(nop) COPY file:e57eef017a414c...   4.62 kB
    <missing>           2 weeks ago         /bin/sh -c #(nop) COPY file:abbcbf84dc17ee...   1.27 kB
    <missing>           2 weeks ago         /bin/sh -c #(nop) COPY file:5c182727343494...   2.12 kB
    <missing>           2 weeks ago         /bin/sh -c #(nop) COPY file:7b307b62e82255...   1.62 kB
    <missing>           2 weeks ago         /bin/sh -c set -x     && addgroup --system...   61.2 MB
    <missing>           2 weeks ago         /bin/sh -c #(nop)  ENV PKG_RELEASE=1~bullseye   0 B
    <missing>           2 weeks ago         /bin/sh -c #(nop)  ENV NJS_VERSION=0.7.7        0 B
    <missing>           2 weeks ago         /bin/sh -c #(nop)  ENV NGINX_VERSION=1.23.2     0 B
    <missing>           2 weeks ago         /bin/sh -c #(nop)  LABEL maintainer=NGINX ...   0 B
    <missing>           2 weeks ago         /bin/sh -c #(nop)  CMD ["bash"]                 0 B
    <missing>           2 weeks ago         /bin/sh -c #(nop) ADD file:d08e242792caa7f...   80.5 MB
    [root@localhost ~]# docker inspect nginx
    [
        {
            "Id": "sha256:88736fe827391462a4db99252117f136b2b25d1d31719006326a437bb40cb12d",
            "RepoTags": [
                "docker.io/nginx:latest"
            ],
            "RepoDigests": [
                "docker.io/nginx@sha256:e209ac2f37c70c1e0e9873a5f7231e91dcd83fdf1178d8ed36c2ec09974210ba"
            ],
            "Parent": "",
            "Comment": "",
            "Created": "2022-11-15T13:14:32.170016733Z",
            "Container": "ef7ac270db8490100ca29b63b039f34d8bc4e9d0bc5b4a7bb986d8086cffce16",
            "ContainerConfig": {
                "Hostname": "ef7ac270db84",
                "Domainname": "",
                "User": "",
                "AttachStdin": false,
                "AttachStdout": false,
                "AttachStderr": false,
                "ExposedPorts": {
                    "80/tcp": {}
                },
                "Tty": false,
                "OpenStdin": false,
                "StdinOnce": false,
                "Env": [
                    "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                    "NGINX_VERSION=1.23.2",
                    "NJS_VERSION=0.7.7",
                    "PKG_RELEASE=1~bullseye"
                ],
                "Cmd": [
                    "/bin/sh",
                    "-c",
                    "#(nop) ",
                    "CMD [\"nginx\" \"-g\" \"daemon off;\"]"
                ],
                "Image": "sha256:60dafcaed78a384237ed956c07eed39793b5f8862195323929417177e3ee9fa7",
                "Volumes": null,
                "WorkingDir": "",
                "Entrypoint": [
                    "/docker-entrypoint.sh"
                ],
                "OnBuild": null,
                "Labels": {
                    "maintainer": "NGINX Docker Maintainers "
                },
                "StopSignal": "SIGQUIT"
            },
            "DockerVersion": "20.10.12",
            "Author": "",
            "Config": {
                "Hostname": "",
                "Domainname": "",
                "User": "",
                "AttachStdin": false,
                "AttachStdout": false,
                "AttachStderr": false,
                "ExposedPorts": {
                    "80/tcp": {}
                },
                "Tty": false,
                "OpenStdin": false,
                "StdinOnce": false,
                "Env": [
                    "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                    "NGINX_VERSION=1.23.2",
                    "NJS_VERSION=0.7.7",
                    "PKG_RELEASE=1~bullseye"
                ],
                "Cmd": [
                    "nginx",
                    "-g",
                    "daemon off;"
                ],
                "Image": "sha256:60dafcaed78a384237ed956c07eed39793b5f8862195323929417177e3ee9fa7",
                "Volumes": null,
                "WorkingDir": "",
                "Entrypoint": [
                    "/docker-entrypoint.sh"
                ],
                "OnBuild": null,
                "Labels": {
                    "maintainer": "NGINX Docker Maintainers "
                },
                "StopSignal": "SIGQUIT"
            },
            "Architecture": "amd64",
            "Os": "linux",
            "Size": 141767480,
            "VirtualSize": 141767480,
            "GraphDriver": {
                "Name": "overlay2",
                "Data": {
                    "LowerDir": "/var/lib/docker/overlay2/97493a1a8b79f5fa5995298ffa63ada448c9809c20b1ad9a26090900ce8e8001/diff:/var/lib/docker/overlay2/3e6953ea3ddefc3fe32c31151935ebd49a74cbab3d7b16262a62d4b753dd416b/diff:/var/lib/docker/overlay2/5594f280528430e925f3ef35b6a91674ff1be95a721a3166548602a24916f63d/diff:/var/lib/docker/overlay2/c57ac6832a9a6084c6a58136092600f9edd6586d20f6ef5eaae860ad034a80de/diff:/var/lib/docker/overlay2/6808292a4f65f555b987700ef19d8e80f36c8038cc22a918ec878ebba66d283c/diff",
                    "MergedDir": "/var/lib/docker/overlay2/123e463d6c5d6be68ae28d44cf7a94609a2ea65aec9a2504279c284a79a0ccd5/merged",
                    "UpperDir": "/var/lib/docker/overlay2/123e463d6c5d6be68ae28d44cf7a94609a2ea65aec9a2504279c284a79a0ccd5/diff",
                    "WorkDir": "/var/lib/docker/overlay2/123e463d6c5d6be68ae28d44cf7a94609a2ea65aec9a2504279c284a79a0ccd5/work"
                }
            },
            "RootFS": {
                "Type": "layers",
                "Layers": [
                    "sha256:ec4a38999118b78eab6899b913a548cb0b2c9b68fd05aff846a56b628b597f38",
                    "sha256:f7ed3797e2964e58da7a396e8b1a98b2aaa84a6190f5fabc57123a92fca78469",
                    "sha256:f86e88a471f4cf2a042312c5c2472838b1c806c5ee83b37a2b2e436c76fcdfb7",
                    "sha256:5a5bafd53f766cdebd7cf6ec4d07dda9300b5d5906a7afa0829b41899a82ea6e",
                    "sha256:e2d75d87993c69701dab59a11e3c081b5d42129048df04e01b50c11bebcf0a5c",
                    "sha256:6cffb086835a28fcada50f39aed18e189ae4d3c139717411d477763274412414"
                ]
            }
        }
    ]
    [root@localhost ~]# docker save nginx -o nginx.tar
    [root@localhost ~]# docker images
    REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
    docker.io/nginx     latest              88736fe82739        2 weeks ago         142 MB
    [root@localhost ~]# ll -h nginx.tar
    -rw-------. 1 root root 140M Dec  5 11:19 nginx.tar
    
    [root@localhost ~]# docker save nginx -o nginx.tar
    [root@localhost ~]# docker images
    REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
    docker.io/nginx     latest              88736fe82739        2 weeks ago         142 MB
    [root@localhost ~]# ll -h nginx.tar
    -rw-------. 1 root root 140M Dec  5 11:19 nginx.tar
    [root@localhost ~]# tar xf nginx.tar /
    bin/   dev/   home/  lib64/ mnt/   proc/  run/   srv/   tmp/   var/
    boot/  etc/   lib/   media/ opt/   root/  sbin/  sys/   usr/
    [root@localhost ~]# tar xf nginx.tar /
    bin/   dev/   home/  lib64/ mnt/   proc/  run/   srv/   tmp/   var/
    boot/  etc/   lib/   media/ opt/   root/  sbin/  sys/   usr/
    [root@localhost ~]# tar xf nginx.tar /data
    tar: /data: Not found in archive
    tar: Exiting with failure status due to previous errors
    [root@localhost ~]# tar xf nginx.tar -C /data
    tar: /data: Cannot open: No such file or directory
    tar: Error is not recoverable: exiting now
    [root@localhost ~]#
    [root@localhost ~]# mkdir /data
    [root@localhost ~]# tar xf nginx.tar -C /data
    tar: manifest.json: implausibly old time stamp 1970-01-01 08:00:00
    tar: repositories: implausibly old time stamp 1970-01-01 08:00:00
    [root@localhost ~]# ll /data/
    total 16
    drwxr-xr-x. 2 root root   50 Nov 15 21:14 20bec44fe1fb816ca15cdcce702675280dbb9d7ba11835c8b94d60ea634be5ab
    drwxr-xr-x. 2 root root   50 Nov 15 21:14 2ba32b890c3cd06317f5f01a7b0ce5310c834356f6555090b24b89af9efc9d9b
    -rw-r--r--. 1 root root 7657 Nov 15 21:14 88736fe827391462a4db99252117f136b2b25d1d31719006326a437bb40cb12d.json
    drwxr-xr-x. 2 root root   50 Nov 15 21:14 8c0c09a2ed8f274683157b09b98d5483c6194d52f2880b3a01b1f9fe37bf65a4
    drwxr-xr-x. 2 root root   50 Nov 15 21:14 9c77421b41ebfc41a9d4d072ec73b6b9f36901f6736049f80296167e6f7ab166
    drwxr-xr-x. 2 root root   50 Nov 15 21:14 c51e3fa40309e4a5b332b4fb98d76594d665a985a5c2e1a92bb77686c839f13d
    drwxr-xr-x. 2 root root   50 Nov 15 21:14 fddb072856944e7854fa487da47ca82975e37f04cc34201910e66eff4e8b5e8b
    -rw-r--r--. 1 root root  596 Jan  1  1970 manifest.json
    -rw-r--r--. 1 root root   98 Jan  1  1970 repositories
    [root@localhost ~]# cat /data/manifest.json
    [{"Config":"88736fe827391462a4db99252117f136b2b25d1d31719006326a437bb40cb12d.json","RepoTags":["docker.io/nginx:latest"],"Layers":["20bec44fe1fb816ca15cdcce702675280dbb9d7ba11835c8b94d60ea634be5ab/layer.tar","c51e3fa40309e4a5b332b4fb98d76594d665a985a5c2e1a92bb77686c839f13d/layer.tar","8c0c09a2ed8f274683157b09b98d5483c6194d52f2880b3a01b1f9fe37bf65a4/layer.tar","9c77421b41ebfc41a9d4d072ec73b6b9f36901f6736049f80296167e6f7ab166/layer.tar","2ba32b890c3cd06317f5f01a7b0ce5310c834356f6555090b24b89af9efc9d9b/layer.tar","fddb072856944e7854fa487da47ca82975e37f04cc34201910e66eff4e8b5e8b/layer.tar"]}]
    [root@localhost ~]# cd /data/
    20bec44fe1fb816ca15cdcce702675280dbb9d7ba11835c8b94d60ea634be5ab/
    2ba32b890c3cd06317f5f01a7b0ce5310c834356f6555090b24b89af9efc9d9b/
    88736fe827391462a4db99252117f136b2b25d1d31719006326a437bb40cb12d.json
    8c0c09a2ed8f274683157b09b98d5483c6194d52f2880b3a01b1f9fe37bf65a4/
    9c77421b41ebfc41a9d4d072ec73b6b9f36901f6736049f80296167e6f7ab166/
    c51e3fa40309e4a5b332b4fb98d76594d665a985a5c2e1a92bb77686c839f13d/
    fddb072856944e7854fa487da47ca82975e37f04cc34201910e66eff4e8b5e8b/
    manifest.json
    repositories
    [root@localhost ~]# cd /data/20bec44fe1fb816ca15cdcce702675280dbb9d7ba11835c8b94d60ea634be5ab/
    [root@localhost 20bec44fe1fb816ca15cdcce702675280dbb9d7ba11835c8b94d60ea634be5ab]# ls
    json  layer.tar  VERSION
    [root@localhost 20bec44fe1fb816ca15cdcce702675280dbb9d7ba11835c8b94d60ea634be5ab]# du -sh /data/*
    81M     /data/20bec44fe1fb816ca15cdcce702675280dbb9d7ba11835c8b94d60ea634be5ab
    12K     /data/2ba32b890c3cd06317f5f01a7b0ce5310c834356f6555090b24b89af9efc9d9b
    8.0K    /data/88736fe827391462a4db99252117f136b2b25d1d31719006326a437bb40cb12d.json
    12K     /data/8c0c09a2ed8f274683157b09b98d5483c6194d52f2880b3a01b1f9fe37bf65a4
    16K     /data/9c77421b41ebfc41a9d4d072ec73b6b9f36901f6736049f80296167e6f7ab166
    60M     /data/c51e3fa40309e4a5b332b4fb98d76594d665a985a5c2e1a92bb77686c839f13d
    16K     /data/fddb072856944e7854fa487da47ca82975e37f04cc34201910e66eff4e8b5e8b
    4.0K    /data/manifest.json
    4.0K    /data/repositories
    [root@localhost 20bec44fe1fb816ca15cdcce702675280dbb9d7ba11835c8b94d60ea634be5ab]# cd /data/9c77421b41ebfc41a9d4d072ec73b6b9f36901f6736049f80296167e6f7ab166/
    [root@localhost 9c77421b41ebfc41a9d4d072ec73b6b9f36901f6736049f80296167e6f7ab166]# ls
    json  layer.tar  VERSION
    [root@localhost 9c77421b41ebfc41a9d4d072ec73b6b9f36901f6736049f80296167e6f7ab166]# tar xf layer.tar
    [root@localhost 9c77421b41ebfc41a9d4d072ec73b6b9f36901f6736049f80296167e6f7ab166]# ls
    docker-entrypoint.d  json  layer.tar  VERSION
    [root@localhost 9c77421b41ebfc41a9d4d072ec73b6b9f36901f6736049f80296167e6f7ab166]# cd docker-entrypoint.d/
    [root@localhost docker-entrypoint.d]# ls
    10-listen-on-ipv6-by-default.sh
    [root@localhost docker-entrypoint.d]# cd 10-listen-on-ipv6-by-default.sh
    -bash: cd: 10-listen-on-ipv6-by-default.sh: Not a directory
    [root@localhost docker-entrypoint.d]# ls
    10-listen-on-ipv6-by-default.sh
    [root@localhost docker-entrypoint.d]# cd  /data/20bec44fe1fb816ca15cdcce702675280dbb9d7ba11835c8b94d60ea634be5ab/
    [root@localhost 20bec44fe1fb816ca15cdcce702675280dbb9d7ba11835c8b94d60ea634be5ab]# ls
    json  layer.tar  VERSION
    [root@localhost 20bec44fe1fb816ca15cdcce702675280dbb9d7ba11835c8b94d60ea634be5ab]# tar layer.tar
    tar: invalid option -- 'y'
    Try `tar --help' or `tar --usage' for more information.
    [root@localhost 20bec44fe1fb816ca15cdcce702675280dbb9d7ba11835c8b94d60ea634be5ab]# tar xf layer.tar
    [root@localhost 20bec44fe1fb816ca15cdcce702675280dbb9d7ba11835c8b94d60ea634be5ab]# ls
    bin   dev  home  layer.tar  lib64  mnt  proc  run   srv  tmp  var
    boot  etc  json  lib        media  opt  root  sbin  sys  usr  VERSION
    [root@localhost 20bec44fe1fb816ca15cdcce702675280dbb9d7ba11835c8b94d60ea634be5ab]# cat /etc/i
    init.d/    inittab    inputrc    iproute2/  issue      issue.net
    [root@localhost 20bec44fe1fb816ca15cdcce702675280dbb9d7ba11835c8b94d60ea634be5ab]# cat /etc/i
    init.d/    inittab    inputrc    iproute2/  issue      issue.net
    [root@localhost 20bec44fe1fb816ca15cdcce702675280dbb9d7ba11835c8b94d60ea634be5ab]# cat /etc/init.d/
    cat: /etc/init.d/: Is a directory
    [root@localhost 20bec44fe1fb816ca15cdcce702675280dbb9d7ba11835c8b94d60ea634be5ab]# ls
    bin   dev  home  layer.tar  lib64  mnt  proc  run   srv  tmp  var
    boot  etc  json  lib        media  opt  root  sbin  sys  usr  VERSION
    [root@localhost 20bec44fe1fb816ca15cdcce702675280dbb9d7ba11835c8b94d60ea634be5ab]# cat etc/
    adduser.conf            issue                   rc0.d/
    alternatives/           issue.net               rc1.d/
    apt/                    kernel/                 rc2.d/
    bash.bashrc             ld.so.cache             rc3.d/
    bindresvport.blacklist  ld.so.conf              rc4.d/
    cron.d/                 ld.so.conf.d/           rc5.d/
    cron.daily/             libaudit.conf           rc6.d/
    debconf.conf            localtime               rcS.d/
    debian_version          login.defs              resolv.conf
    default/                logrotate.d/            rmt
    deluser.conf            mke2fs.conf             security/
    dpkg/                   motd                    selinux/
    e2scrub.conf            netconfig               shadow
    environment             nsswitch.conf           shadow-
    fstab                   opt/                    shells
    gai.conf                os-release              skel/
    group                   pam.conf                subgid
    group-                  pam.d/                  subuid
    gshadow                 passwd                  systemd/
    gss/                    passwd-                 terminfo/
    host.conf               profile                 timezone
    hostname                profile.d/              update-motd.d/
    init.d/                 .pwd.lock               xattr.conf
    [root@localhost 20bec44fe1fb816ca15cdcce702675280dbb9d7ba11835c8b94d60ea634be5ab]# cat etc/
    adduser.conf            issue                   rc0.d/
    alternatives/           issue.net               rc1.d/
    apt/                    kernel/                 rc2.d/
    bash.bashrc             ld.so.cache             rc3.d/
    bindresvport.blacklist  ld.so.conf              rc4.d/
    cron.d/                 ld.so.conf.d/           rc5.d/
    cron.daily/             libaudit.conf           rc6.d/
    debconf.conf            localtime               rcS.d/
    debian_version          login.defs              resolv.conf
    default/                logrotate.d/            rmt
    deluser.conf            mke2fs.conf             security/
    dpkg/                   motd                    selinux/
    e2scrub.conf            netconfig               shadow
    environment             nsswitch.conf           shadow-
    fstab                   opt/                    shells
    gai.conf                os-release              skel/
    group                   pam.conf                subgid
    group-                  pam.d/                  subuid
    gshadow                 passwd                  systemd/
    gss/                    passwd-                 terminfo/
    host.conf               profile                 timezone
    hostname                profile.d/              update-motd.d/
    init.d/                 .pwd.lock               xattr.conf
    [root@localhost 20bec44fe1fb816ca15cdcce702675280dbb9d7ba11835c8b94d60ea634be5ab]# cat etc/init.d/
    cat: etc/init.d/: Is a directory
    [root@localhost 20bec44fe1fb816ca15cdcce702675280dbb9d7ba11835c8b94d60ea634be5ab]# cat etc/issue
    Debian GNU/Linux 11 \n \l
    
    [root@localhost 20bec44fe1fb816ca15cdcce702675280dbb9d7ba11835c8b94d60ea634be5ab]#
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 170
    • 171
    • 172
    • 173
    • 174
    • 175
    • 176
    • 177
    • 178
    • 179
    • 180
    • 181
    • 182
    • 183
    • 184
    • 185
    • 186
    • 187
    • 188
    • 189
    • 190
    • 191
    • 192
    • 193
    • 194
    • 195
    • 196
    • 197
    • 198
    • 199
    • 200
    • 201
    • 202
    • 203
    • 204
    • 205
    • 206
    • 207
    • 208
    • 209
    • 210
    • 211
    • 212
    • 213
    • 214
    • 215
    • 216
    • 217
    • 218
    • 219
    • 220
    • 221
    • 222
    • 223
    • 224
    • 225
    • 226
    • 227
    • 228
    • 229
    • 230
    • 231
    • 232
    • 233
    • 234
    • 235
    • 236
    • 237
    • 238
    • 239
    • 240
    • 241
    • 242
    • 243
    • 244
    • 245
    • 246
    • 247
    • 248
    • 249
    • 250
    • 251
    • 252
    • 253
    • 254
    • 255
    • 256
    • 257
    • 258
    • 259
    • 260
    • 261
    • 262
    • 263
    • 264
    • 265
    • 266
    • 267
    • 268
    • 269
    • 270
    • 271
    • 272
    • 273
    • 274
    • 275
    • 276
    • 277
    • 278
    • 279
    • 280
    • 281
    • 282
    • 283
    • 284
    • 285
    • 286
    • 287
    • 288
    • 289
    • 290
    • 291
    • 292
    • 293
    • 294
    • 295
    • 296
    • 297

    搜索查找镜像

    1.官方网站搜索

    官网: http://hub.docker.com

    2.命令行搜索

    Usage: 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服务来帮助编译镜像,可以在互联网上面直接拉取到镜像,减少了繁琐的
    编译过程
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    [root@localhost ~]# docker search nginx
    INDEX       NAME                                                        DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
    docker.io   docker.io/nginx                                             Official build of Nginx.                        17780     [OK]
    docker.io   docker.io/linuxserver/nginx                                 An Nginx container, brought to you by Linu...   182
    docker.io   docker.io/bitnami/nginx                                     Bitnami nginx Docker Image                      146                  [OK]
    docker.io   docker.io/ubuntu/nginx                                      Nginx, a high-performance reverse proxy & ...   69
    docker.io   docker.io/bitnami/nginx-ingress-controller                  Bitnami Docker Image for NGINX Ingress Con...   22                   [OK]
    docker.io   docker.io/rancher/nginx-ingress-controller                                                                  11
    docker.io   docker.io/ibmcom/nginx-ingress-controller                   Docker Image for IBM Cloud Private-CE (Com...   4
    docker.io   docker.io/kasmweb/nginx                                     An Nginx image based off nginx:alpine and ...   4
    docker.io   docker.io/bitnami/nginx-exporter                                                                            3
    docker.io   docker.io/bitnami/nginx-ldap-auth-daemon                                                                    3
    docker.io   docker.io/circleci/nginx                                    This image is for internal use                  2
    docker.io   docker.io/rancher/nginx                                                                                     2
    docker.io   docker.io/rancher/nginx-ingress-controller-defaultbackend                                                   2
    docker.io   docker.io/rapidfort/nginx                                   RapidFort optimized, hardened image for NGINX   2
    docker.io   docker.io/vmware/nginx                                                                                      2
    docker.io   docker.io/bitnami/nginx-intel                                                                               1
    docker.io   docker.io/vmware/nginx-photon                                                                               1
    docker.io   docker.io/wallarm/nginx-ingress-controller                  Kubernetes Ingress Controller with Wallarm...   1
    docker.io   docker.io/continuumio/nginx-ingress-ws                                                                      0
    docker.io   docker.io/ibmcom/nginx-ingress-controller-ppc64le           Docker Image for IBM Cloud Private-CE (Com...   0
    docker.io   docker.io/ibmcom/nginx-ppc64le                              Docker image for nginx-ppc64le                  0
    docker.io   docker.io/rancher/nginx-conf                                                                                0
    docker.io   docker.io/rancher/nginx-ssl                                                                                 0
    docker.io   docker.io/rapidfort/nginx-ib                                RapidFort optimized, hardened image for NG...   0
    docker.io   docker.io/rapidfort/nginx-official                          RapidFort optimized, hardened image for NG...   0
    
    
    ##########################
    #搜索点赞100或者50以上的镜像
    [root@localhost ~]# docker search --filter=stars=100 centos
    INDEX       NAME               DESCRIPTION                                 STARS     OFFICIAL   AUTOMATED
    docker.io   docker.io/centos   DEPRECATED; The official build of CentOS.   7422      [OK]
    [root@localhost ~]# docker search --filter=stars=100 centos
    INDEX       NAME               DESCRIPTION                                 STARS     OFFICIAL   AUTOMATED
    docker.io   docker.io/centos   DEPRECATED; The official build of CentOS.   7422      [OK]
    [root@localhost ~]# docker search --filter=stars=50 centos
    INDEX       NAME               DESCRIPTION                                 STARS     OFFICIAL   AUTOMATED
    docker.io   docker.io/centos   DEPRECATED; The official build of CentOS.   7422      [OK]
    [root@localhost ~]# docker search --filter=stars=50 nginx
    INDEX       NAME                          DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
    docker.io   docker.io/nginx               Official build of Nginx.                        17780     [OK]
    docker.io   docker.io/linuxserver/nginx   An Nginx container, brought to you by Linu...   182
    docker.io   docker.io/bitnami/nginx       Bitnami nginx Docker Image                      146                  [OK]
    docker.io   docker.io/ubuntu/nginx        Nginx, a high-performance reverse proxy & ...   69
    
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48

    镜像加速器配置

    浏览器打开http://cr.console.aliyun.com,登录阿里云账号,点击镜像工具----镜像加速器

    在这里插入图片描述

    查看本地镜像

    格式:

    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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    执行结果的显示信息说明

    REPOSITORY      #镜像所属的仓库名称
    TAG         #镜像版本号(标识符),默认为latest
    IMAGE ID       #镜像唯一ID标识,如果ID相同,说明是同一个镜像有多个名称
    CREATED       #镜像创建时间
    VIRTUAL SIZE    #镜像的大小
    
    • 1
    • 2
    • 3
    • 4
    • 5

    例:

    [root@localhost ~]# docker images
    REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
    docker.io/nginx     latest              88736fe82739        2 weeks ago         142 MB
    [root@localhost ~]# docker images -q
    88736fe82739
    [root@localhost ~]# docker images -a
    REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
    docker.io/nginx     latest              88736fe82739        2 weeks ago         142 MB
    #显示完整的imageid
    [root@localhost ~]# docker images --no-trunc
    REPOSITORY          TAG                 IMAGE ID                                                                  CREATED             SIZE
    docker.io/nginx     latest              sha256:88736fe827391462a4db99252117f136b2b25d1d31719006326a437bb40cb12d   2 weeks ago         142 MB
    
    #查看指定repository的镜像
    [root@localhost ~]# docker images tomcat
    REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
    docker.io/tomcat    latest              1ca69d1bf49a        2 weeks ago         474 MB
    
    ##查看指定镜像的信息
    [root@localhost ~]# podman image inspect nginx
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21

    镜像导入与导出

    docker load [OPTIONS]
    #选项
    -i, --input string   Read from tar archive file, instead of STDIN
    -q, --quiet         Suppress the load output
    
    • 1
    • 2
    • 3
    • 4
    docker load -i /path/file.tar
    docker load < /path/file.tar
    
    • 1
    • 2

    例:将一台主机的所有镜像传到另一台主机

    方法1: 使用image ID导出镜像,在导入后的镜像没有REPOSITORY和TAG,显示为<none>
    [root@ubuntu1804 ~]#docker save `docker images -qa` -o all.tar
    [root@ubuntu1804 ~]#scp all.tar 10.0.0.*:
    [root@centos7 ~]#docker load -i all.tar
    [root@centos7 ~]#docker images
    REPOSITORY         TAG                 IMAGE ID           CREATED             
    SIZE
    <none>             <none>             a77dce18d0ec        10 days ago         
    1.24MB
    <none>             <none>             389fef711851        3 weeks ago         
    5.58MB
    <none>             <none>             300e315adb2f        4 weeks ago         
    209MB
    <none>             <none>             f643c72bc252        6 weeks ago         
    72.9MB
    #方法2: 将所有镜像导入到一个文件中,此方法导入后可以看REPOSITORY和TAG
    [root@ubuntu1804 ~]#docker save `docker images | awk 'NR!=1{print $1":"$2}'` -o 
    backup.tar
    [root@ubuntu1804 ~]#scp backup.tar 10.0.0.**:
    root@ubuntu2004:~# docker load -i backup.tar 
    root@ubuntu2004:~# docker images
    REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
    busybox     uclibc   a77dce18d0ec   10 days ago   1.24MB
    alpine       latest   389fef711851   3 weeks ago   5.58MB
    centos       latest   300e315adb2f   4 weeks ago   209MB
    ubuntu       latest   f643c72bc252   6 weeks ago   72.9MB
    #方法3:将所有镜像导入到一个文件中,此方法导入后可以看REPOSITORY和TAG
    [root@centos8 ~]#docker image save `docker image ls --format "{{.Repository}}:
    {{.Tag}}"` -o all.tar
    [root@centos8 ~]#scp all.tar 10.0.0.***:/data
    [root@ubuntu1804 ~]#docker load -i /data/all.tar
    [root@ubuntu1804 ~]#docker images
    REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
    busybox     uclibc   a77dce18d0ec   10 days ago   1.24MB
    alpine       latest   389fef711851   3 weeks ago   5.58MB
    centos       latest   300e315adb2f   4 weeks ago   209MB
    ubuntu       latest   f643c72bc252   6 weeks ago   72.9MB
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37

    删除镜像

    [root@localhost ~]# dcoker rmi feb5d9f
    -bash: dcoker: command not found
    [root@localhost ~]# docker rmi feb5d9f
    Untagged: docker.io/hello-world:latest
    Untagged: docker.io/hello-world@sha256:faa03e786c97f07ef34423fccceeec2398ec8a5759259f94d99078f264e9d7af
    Deleted: sha256:feb5d9fea6a5e9606aa995e879d862b825965ba48de054caab5ef356dc6b3412
    Deleted: sha256:e07ee1baac5fae6a26f30cabfe54a36d3402f96afda318fe0a96cec4ca393359
    [root@localhost ~]# docker images
    REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
    docker.io/alpine    latest              49176f190c7e        12 days ago         7.05 MB
    docker.io/busybox   latest              9d5226e6ce3f        2 weeks ago         1.24 MB
    docker.io/nginx     latest              88736fe82739        2 weeks ago         142 MB
    docker.io/tomcat    latest              1ca69d1bf49a        2 weeks ago         474 MB
    [root@localhost ~]#
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15

    镜像打标签

    docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]
    
    • 1
    [root@localhost ~]# docker tag alpine alpine:3.22
    [root@localhost ~]# docker images
    REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
    alpine              3.22                49176f190c7e        12 days ago         7.05 MB
    docker.io/alpine    latest              49176f190c7e        12 days ago         7.05 MB
    docker.io/busybox   latest              9d5226e6ce3f        2 weeks ago         1.24 MB
    docker.io/nginx     latest              88736fe82739        2 weeks ago         142 MB
    docker.io/tomcat    latest              1ca6
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    常见操作: 搜索、下载、导出、导入、删除

    docker search centos #搜索
    docker pull alpine #下载
    docker images  #查看
    docker save > /opt/centos.tar #centos #导出镜像
    docker load -i /opt/centos.tar  #导入本地镜像
    docker rmi 镜像ID/镜像名称  #删除指定ID的镜像,此镜像对应容器正启动镜像不能被删除,除非将容器
    全部关闭
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    
    常见操作: 搜索、下载、导出、导入、删除
    
    ```bash
    docker search centos #搜索
    docker pull alpine #下载
    docker images  #查看
    docker save > /opt/centos.tar #centos #导出镜像
    docker load -i /opt/centos.tar  #导入本地镜像
    docker rmi 镜像ID/镜像名称  #删除指定ID的镜像,此镜像对应容器正启动镜像不能被删除,除非将容器
    全部关闭
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
  • 相关阅读:
    基于单片机的自动变速箱电控系统
    实际编译运行tensorflow Lite Microcontroller的例子《MCU嵌入式AI开发笔记》(第8集)
    蓝鹏精准测量系统 助力圆钢负公差轧制
    C++11智能指针weak_ptr
    sklearn 笔记 BallTree/KD Tree
    JavaWeb JavaScript
    DIV简单个人静态HTML网页设计作品 WEB静态个人介绍网页模板代码 DW个人网站制作成品 期末网页制作与实现...
    你是否还迷茫要不要学习Linux?
    Vue3.x新特性 Vue3新功能(详细)
    java项目使用GRPC框架
  • 原文地址:https://blog.csdn.net/weixin_45423952/article/details/128188759