美文网首页【原创】Docker实战系列
Docke管理-镜像的基本管理

Docke管理-镜像的基本管理

作者: 复苏的兵马俑 | 来源:发表于2020-04-17 09:29 被阅读0次

1、Docker体系结构

Docker体系结构

2、获取镜像

[root@server ~]# docker search centos
NAME                               DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
centos                             The official build of CentOS.                   5944                [OK]  
ansible/centos7-ansible            Ansible on Centos7                              128                                     [OK]
jdeathe/centos-ssh                 OpenSSH / Supervisor / EPEL/IUS/SCL Repos - …   114                                     [OK]
consol/centos-xfce-vnc             Centos container with "headless" VNC session…   114                                     [OK]
centos/mysql-57-centos7            MySQL 5.7 SQL database server                   74                        
imagine10255/centos6-lnmp-php56    centos6-lnmp-php56                              58                                      [OK]
tutum/centos                       Simple CentOS docker image with SSH access      45                        
centos/postgresql-96-centos7       PostgreSQL is an advanced Object-Relational …   43                        
kinogmt/centos-ssh                 CentOS with SSH                                 29                                      [OK]
pivotaldata/centos-gpdb-dev        CentOS image for GPDB development. Tag names…   11                        
guyton/centos6                     From official centos6 container with full up…   10                                      [OK]
centos/tools                       Docker image that has systems administration…   6                                       [OK]
drecom/centos-ruby                 centos ruby                                     6                                       [OK]
pivotaldata/centos                 Base centos, freshened up a little with a Do…   4                         
darksheer/centos                   Base Centos Image -- Updated hourly             3                                       [OK]
pivotaldata/centos-mingw           Using the mingw toolchain to cross-compile t…   3                         
mamohr/centos-java                 Oracle Java 8 Docker image based on Centos 7    3                                       [OK]
pivotaldata/centos-gcc-toolchain   CentOS with a toolchain, but unaffiliated wi…   3                         
miko2u/centos6                     CentOS6 日本語環境                               2                                       [OK]
mcnaughton/centos-base             centos base image                               1                                       [OK]
blacklabelops/centos               CentOS Base Image! Built and Updates Daily!     1                                       [OK]
indigo/centos-maven                Vanilla CentOS 7 with Oracle Java Developmen…   1                                       [OK]
pivotaldata/centos7-dev            CentosOS 7 image for GPDB development           0                         
pivotaldata/centos6.8-dev          CentosOS 6.8 image for GPDB development         0                         
smartentry/centos                  centos with smartentry                          0                                       [OK]
[root@Server ~]# vi list_img_tags.sh
#!/bin/sh

repo_url=https://registry.hub.docker.com/v1/repositories
image_name=$1

curl -s ${repo_url}/${image_name}/tags | json_reformat | grep name | awk '{print $2}' | sed -e 's/"//g'
[root@Server ~]# sh list_img_tags.sh centos
latest
5
5.11
6
6.10
6.6
6.7
6.8
6.9
7
7.0.1406
7.1.1503
7.2.1511
7.3.1611
7.4.1708
7.5.1804
7.6.1810
7.7.1908
8
8.1.1911
centos5
centos5.11
centos6
centos6.10
centos6.6
centos6.7
centos6.8
centos6.9
centos7
centos7.0.1406
centos7.1.1503
centos7.2.1511
centos7.3.1611
centos7.4.1708
centos7.5.1804
centos7.6.1810
centos7.7.1908
centos8
centos8.1.1911
[root@Server ~]# docker pull centos
Using default tag: latest
latest: Pulling from library/centos
8a29a15cefae: Pull complete
Digest: sha256:fe8d824220415eed5477b63addf40fb06c3b049404242b31982106ac204f6700
Status: Downloaded newer image for centos:latest
docker.io/library/centos:latest
[root@server ~]# docker pull centos:7.7.1908
7.7.1908: Pulling from library/centos
f34b00c7da20: Pull complete
Digest: sha256:50752af5182c6cd5518e3e91d48f7ff0cba93d5d760a67ac140e2d63c4dd9efc
Status: Downloaded newer image for centos:7.7.1908
docker.io/library/centos:7.7.1908
[root@Server ~]# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
123275d6e508: Pull complete
9a5d769f04f8: Pull complete
faad4f49180d: Pull complete
Digest: sha256:4a1f25606ce84be14bb5b4a4e11825d9ce78affeec62545d0a027dc8a1b2ce76
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest

3、查看镜像基本信息

[root@Server ~]# docker image ls
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
nginx               latest              5a8dfb2ca731        15 hours ago        127MB
centos              latest              470671670cac        3 months ago        237MB
centos              7.7.1908            08d05d1d5859        5 months ago        204MB
[root@Server ~]# docker image ls --no-trunc
REPOSITORY          TAG                 IMAGE ID                                                                  CREATED             SIZE
nginx               latest              sha256:5a8dfb2ca7312ee39433331b11d92f45bb19d7809f7c0ff19e1d01a2c131e959   15 hours ago        127MB
centos              latest              sha256:470671670cac686c7cf0081e0b37da2e9f4f768ddc5f6a26102ccd1c6954c1ee   3 months ago        237MB
centos              7.7.1908            sha256:08d05d1d5859ebcfb3312d246e2082e46cb307f0e896c9ac097185f0b0b19e56   5 months ago        204MB

标识镜像唯一性的方法:
   a)REPOSITORY:TAG
   比如:centos:latest、centos:8.1.1911
   b)IMAGE ID(sha256:64位的号码,默认只截取12位)
   比如:sha256:470671670cac686c7cf0081e0b37da2e9f4f768ddc5f6a26102ccd1c6954c1ee,截取后的IMAGE ID为470671670cac

4、查看镜像详细信息

[root@Server ~]# docker image inspect centos:latest
[
    {
        "Id": "sha256:470671670cac686c7cf0081e0b37da2e9f4f768ddc5f6a26102ccd1c6954c1ee",
        "RepoTags": [
            "centos:latest"
        ],
        "RepoDigests": [
            "centos@sha256:fe8d824220415eed5477b63addf40fb06c3b049404242b31982106ac204f6700"
        ],
        "Parent": "",
        "Comment": "",
        "Created": "2020-01-18T00:26:46.850750902Z",
        "Container": "57333b28d93d47fedc0cc5c995092b9266fa4b73b64f3f88d42a08e46f1aab48",
        "ContainerConfig": {
            "Hostname": "57333b28d93d",
            "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 [\"/bin/bash\"]"
            ],
            "ArgsEscaped": true,
            "Image": "sha256:0fff7846fd29d8959680f5c1ed8ee2f30197a479c0f73a88dedc0f0755d3277d",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": {
                "org.label-schema.build-date": "20200114",
                "org.label-schema.license": "GPLv2",
                "org.label-schema.name": "CentOS Base Image",
                "org.label-schema.schema-version": "1.0",
                "org.label-schema.vendor": "CentOS",
                "org.opencontainers.image.created": "2020-01-14 00:00:00-08:00",
                "org.opencontainers.image.licenses": "GPL-2.0-only",
                "org.opencontainers.image.title": "CentOS Base Image",
                "org.opencontainers.image.vendor": "CentOS"
            }
        },
        "DockerVersion": "18.06.1-ce",
        "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": [
                "/bin/bash"
            ],
            "ArgsEscaped": true,
            "Image": "sha256:0fff7846fd29d8959680f5c1ed8ee2f30197a479c0f73a88dedc0f0755d3277d",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": {
                "org.label-schema.build-date": "20200114",
                "org.label-schema.license": "GPLv2",
                "org.label-schema.name": "CentOS Base Image",
                "org.label-schema.schema-version": "1.0",
                "org.label-schema.vendor": "CentOS",
                "org.opencontainers.image.created": "2020-01-14 00:00:00-08:00",
                "org.opencontainers.image.licenses": "GPL-2.0-only",
                "org.opencontainers.image.title": "CentOS Base Image",
                "org.opencontainers.image.vendor": "CentOS"
            }
        },
        "Architecture": "amd64",
        "Os": "linux",
        "Size": 237117212,
        "VirtualSize": 237117212,
        "GraphDriver": {
            "Data": {
                "MergedDir": "/var/lib/docker/overlay2/7fdf0a9f17d326c175d105694d59a839c57a25f4f16647d2630596d2f0a442e5/merged",
                "UpperDir": "/var/lib/docker/overlay2/7fdf0a9f17d326c175d105694d59a839c57a25f4f16647d2630596d2f0a442e5/diff",
                "WorkDir": "/var/lib/docker/overlay2/7fdf0a9f17d326c175d105694d59a839c57a25f4f16647d2630596d2f0a442e5/work"
            },
            "Name": "overlay2"
        },
        "RootFS": {
            "Type": "layers",
            "Layers": [
                "sha256:0683de2821778aa9546bf3d3e6944df779daba1582631b7ea3517bb36f9e4007"
            ]
        },
        "Metadata": {
            "LastTagTime": "0001-01-01T00:00:00Z"
        }
    }
]

[root@Server ~]# docker image ls -q
5a8dfb2ca731
470671670cac
08d05d1d5859

5、镜像的导入和导出

[root@Server ~]# docker image save centos:7.7.1908 > /mnt/ubuntu7.7.19008.tar
[root@Server ~]# ls -l /mnt/ubuntu7.7.19008.tar
-rw-r--r-- 1 root root 211785728 Apr 17 09:05 /mnt/ubuntu7.7.19008.tar
[root@Server ~]# docker image ls
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
nginx               latest              5a8dfb2ca731        15 hours ago        127MB
centos              latest              470671670cac        3 months ago        237MB
centos              7.7.1908            08d05d1d5859        5 months ago        204MB
[root@Server ~]# docker image rm centos:7.7.1908
Untagged: centos:7.7.1908
Untagged: centos@sha256:50752af5182c6cd5518e3e91d48f7ff0cba93d5d760a67ac140e2d63c4dd9efc
Deleted: sha256:08d05d1d5859ebcfb3312d246e2082e46cb307f0e896c9ac097185f0b0b19e56
Deleted: sha256:034f282942cd6c3abf9384601a57f080f8f75cc7f58527db8e07573d9d14ab46
[root@Server ~]# docker image ls
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
nginx               latest              5a8dfb2ca731        15 hours ago        127MB
centos              latest              470671670cac        3 months ago        237MB
[root@Server ~]# docker image load -i /mnt/ubuntu7.7.19008.tar
034f282942cd: Loading layer  211.8MB/211.8MB
Loaded image: centos:7.7.1908
[root@Server ~]# docker image ls
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
nginx               latest              5a8dfb2ca731        15 hours ago        127MB
centos              latest              470671670cac        3 months ago        237MB
centos              7.7.1908            08d05d1d5859        5 months ago        204MB

6、删除镜像

[root@Server ~]# docker image rm centos:7.7.1908
Untagged: centos:7.7.1908
Untagged: centos@sha256:50752af5182c6cd5518e3e91d48f7ff0cba93d5d760a67ac140e2d63c4dd9efc
Deleted: sha256:08d05d1d5859ebcfb3312d246e2082e46cb307f0e896c9ac097185f0b0b19e56
Deleted: sha256:034f282942cd6c3abf9384601a57f080f8f75cc7f58527db8e07573d9d14ab46
[root@Server ~]# docker image ls
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
nginx               latest              5a8dfb2ca731        15 hours ago        127MB
centos              latest              470671670cac        3 months ago        237MB
[root@Server ~]# docker image rm -f `docker image ls -q`
Untagged: nginx:latest
Untagged: nginx@sha256:4a1f25606ce84be14bb5b4a4e11825d9ce78affeec62545d0a027dc8a1b2ce76
Deleted: sha256:5a8dfb2ca7312ee39433331b11d92f45bb19d7809f7c0ff19e1d01a2c131e959
Deleted: sha256:eede83f79a434879440e1f6f6f98a135b38057a35ddcdace715ae1bddcd7a884
Deleted: sha256:fa994cfd7aeedcd46b70cf30fea0ccf9f59f990bbb86bfa9b7c02d7ff2a833eb
Deleted: sha256:b60e5c3bcef2f42ec42648b3acf7baf6de1fa780ca16d9180f3b4a3f266fe7bc
Untagged: centos:latest
Untagged: centos@sha256:fe8d824220415eed5477b63addf40fb06c3b049404242b31982106ac204f6700
Deleted: sha256:470671670cac686c7cf0081e0b37da2e9f4f768ddc5f6a26102ccd1c6954c1ee
Deleted: sha256:0683de2821778aa9546bf3d3e6944df779daba1582631b7ea3517bb36f9e4007
Untagged: centos:7.7.1908
Deleted: sha256:08d05d1d5859ebcfb3312d246e2082e46cb307f0e896c9ac097185f0b0b19e56
Deleted: sha256:034f282942cd6c3abf9384601a57f080f8f75cc7f58527db8e07573d9d14ab46
[root@Server ~]# docker image ls
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE

相关文章

网友评论

    本文标题:Docke管理-镜像的基本管理

    本文链接:https://www.haomeiwen.com/subject/bwddvhtx.html