docker镜像管理

2023-05-16

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 <docker-maint@nginx.com>"
            },
            "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 <docker-maint@nginx.com>"
            },
            "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.官方网站搜索

官网: 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服务来帮助编译镜像,可以在互联网上面直接拉取到镜像,减少了繁琐的
编译过程
[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


镜像加速器配置

浏览器打开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

执行结果的显示信息说明

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

例:

[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

镜像导入与导出

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

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

方法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

删除镜像

[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 ~]#

镜像打标签

docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]
[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

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

docker search centos #搜索
docker pull alpine #下载
docker images  #查看
docker save > /opt/centos.tar #centos #导出镜像
docker load -i /opt/centos.tar  #导入本地镜像
docker rmi 镜像ID/镜像名称  #删除指定ID的镜像,此镜像对应容器正启动镜像不能被删除,除非将容器
全部关闭

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

```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的镜像,此镜像对应容器正启动镜像不能被删除,除非将容器
全部关闭
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

docker镜像管理 的相关文章

随机推荐

  • SQL-常见的聚合函数有哪些?

    聚合函数 聚合函数对一组值执行计算并返回单一的值 求个数 记录数 项目数等 xff1a count count 的用法 span class token function COUNT span span class token punctu
  • Vue之v-model双向绑定原理---kalrry

    Vue之v model双向绑定原理 kalrry 一 简介二 表单实现双向绑定1 原理2 实现 三 组件上的双向绑定1 原理2 实现3 实例 一 简介 v model实现双向绑定的语法糖 xff0c 常用于表单与组件之间的数据双向绑定 二
  • Qt开发遇到的坑---kalrry

    Qt开发遇到的坑 kalrry 一 依赖引入坑二 Qt在Debug时报错1 编译器是 MSVC 还是 MinGW 2 编译器 32位 还是 64位 三 Qt 43 MSVC编译后中文乱码四 不能将const char 类型的值分配到cons
  • Sinutrain下载安装与开启OPC UA---kalrry

    Sinumerik下载安装与开启OPC UA kalrry 前言一 安装前准备二 Win7安装1 软件安装2 开启授权3 文件配置4 客户端连接 三 Win10 11安装四 启动后使用五 启动OPC UA 前言 本教程只适用于 Sinutr
  • Qt第三方QCustomPlot的使用---kalrry

    Qt第三方QCustomPlot的使用 kalrry 一 参考博客End 例子 一 参考博客 QCustomPlot中图例的相关设置QCustomPlot使用手册QCustomPlot中图例的相关设置QCustomPlot更改图例legen
  • 【物联网树莓派毕设01】树莓派4B快速实现VNC连接

    一 前言 最近准备开始做毕设了 xff0c 想着找个地方记录一下遇到的问题 xff0c 怎么解决的 xff0c 希望能够给有需要的人一些帮助 xff0c 有什么问题还请指正 这次毕设选题是基于物联网技术的酒店管理系统 xff0c 其实是基于
  • 不忘初心牢记使命文化励志标语墙贴——个性一百剪纸

    不忘初心牢记使命手工剪纸 个性一百定制服务中心 xff0c 可快速定制各类家居家具用品 工艺礼品 图案造型 xff0c 提供从构思到设计到制作一条龙服务 xff0c 您敢想我们敢做 不忘初心牢记使命绘画贴纸 我们不局限于某种商品 xff0c
  • 动态建模——UML活动图

    1 活动图 xff1a 展示了动作或活动的执行步骤及结果 2 作用 xff1a xff08 1 xff09 描述在用例描述时 xff0c 用例的实例是如何让执行动作 xff0c 改变对象状态的 xff08 2 xff09 可以清晰的展示出活
  • 华为交换机常用命令(一)

    历史命名查询 display history command 配置主机名 sys sysname xxx 状态信息查询 display version display users 进入接口模式并查看信息 int g0 0 1 dis thi
  • NoSQL之 Redis配置与优化

    NoSQL之 Redis配置与优化 关系数据库与非关系型数据库关系型数据库和非关系型数据库区别 Redis简介Redis 安装部署Redis 命令工具Redis 数据库常用命令 Redis 高可用Redis 持久化RDB 持久化AOF 持久
  • MQ-2烟雾浓度传感器(STM32F103)

    本实验是通过串口调试助手显示STM32F103C8T6采集到MQ 2传感器的电压值 一 概述 1 简介 MQ 2可用于家庭和工厂的气体泄漏监装置 xff0c 适宜于液化气 丁烷 丙烷 甲烷 酒精 烟雾等的探测 它的优点是灵敏度高 响应快 稳
  • Java-异常

    什么是异常 xff1f 异常是指程序运行时 xff0c 导致正常流程被中断的事件 异常分类 可查异常 xff1a CheckedException xff08 要么try catch住 要么往外抛 xff0c 谁调用 xff0c 谁处理 如
  • 51单片机学习篇-- --蜂鸣器的使用

    开篇先说一句废话 本旺名字叫萨摩耶 xff0c xff0c Please 叫我旺财 xff0c xff0c xff0c 哈哈 xff0c 招财进宝嘛 xff01 蜂鸣器是个啥 蜂鸣器一般分为两种 xff0c 一种是无源蜂鸣器 xff0c 一
  • 51单片机学习篇-- --基于51单片机的串口通信协议

    开篇先说一句废话 本旺名字叫萨摩耶 xff0c xff0c Please 叫我旺财 xff0c xff0c xff0c 哈哈 xff0c 招财进宝嘛 xff01 开篇 计算机按照下行数据通信协议 xff0c 串口发送数据 xff0c 地址为
  • 卸载rancher出现的问题

    卸载rancher出现如下报错 error unable to retrieve the complete list of server APIs custom metrics k8s io v1beta1 the server is cu
  • docker审计日志过大导致磁盘IO

    问题 xff1a 节点发生磁盘io 节点审计日志量较大 xff0c 由于操作系统内核缺陷 xff0c 会低概率出现io卡主 影响版本 xff1a v1 15 11 v 1 17 9 查看节点是否有问题 1 登录节点 2 如果有类似下图的回显
  • linux 环境命令随记

    sh steve bourne bash bourne again shell gpl centos和ubuntu 默认使用 csh c shell C语言风格 tcsh ksh xff1a korb shell aix默认shell zs
  • sed命令的使用

    sed命令 格式 sed 选项 脚本命令 文件名 选项 n 使用安静silent模式 在一般sed的用法中 xff0c 所有来自stdin的内容一般都会被列出到屏幕上 但如果加上 n参数后 xff0c 则只有经过sed特殊处理的那一行 或者
  • docker安装和info信息

    docker 容器的历史 xff1a 1 Chroot Jail 就是我们常见的 chroot 命令的用法 它在 1979 年的时候就出现了 xff0c 被认为是最早的容器化技术之一 它可以把一个进程的文件系统隔离起来 2 The Free
  • docker镜像管理

    docker镜像管理 镜像结构和原理 镜像就是创建容器的模版 xff0c 含有容器启动所需要的文件系统及所需要的内容 xff0c 因此镜像主要用于方便和快速创建启动容器 镜像结构 xff1a 一个典型的 Linux文件系统由 bootfs