其他分享
首页 > 其他分享> > Docker之docker镜像管理

Docker之docker镜像管理

作者:互联网

一 镜像结构和原理

1.1 Docker镜像原理

1.2 Docker镜像的结构

二 搜索镜像

点击查看代码
root@ubuntu:~# docker search nginx
NAME                              DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
nginx                             Official build of Nginx.                        15725     [OK]       
jwilder/nginx-proxy               Automated Nginx reverse proxy for docker con…   2088                 [OK]
richarvey/nginx-php-fpm           Container running Nginx + PHP-FPM capable of…   818                  [OK]
jc21/nginx-proxy-manager          Docker container for managing Nginx proxy ho…   266                  
linuxserver/nginx                 An Nginx container, brought to you by LinuxS…   159                  
tiangolo/nginx-rtmp               Docker image with Nginx using the nginx-rtmp…   142                  [OK]
jlesage/nginx-proxy-manager       Docker container for Nginx Proxy Manager        142                  [OK]
alfg/nginx-rtmp                   NGINX, nginx-rtmp-module and FFmpeg from sou…   110                  [OK]
jasonrivers/nginx-rtmp            Docker images to host RTMP streams using NGI…   95                   [OK]
nginxdemos/hello                  NGINX webserver that serves a simple page co…   76                   [OK]
privatebin/nginx-fpm-alpine       PrivateBin running on an Nginx, php-fpm & Al…   59                   [OK]
nginx/nginx-ingress               NGINX and  NGINX Plus Ingress Controllers fo…   55                   
nginxinc/nginx-unprivileged       Unprivileged NGINX Dockerfiles                  54                   
staticfloat/nginx-certbot         Opinionated setup for automatic TLS certs lo…   25                   [OK]
nginxproxy/nginx-proxy            Automated Nginx reverse proxy for docker con…   23                   
nginx/nginx-prometheus-exporter   NGINX Prometheus Exporter for NGINX and NGIN…   21                   
schmunk42/nginx-redirect          A very simple container to redirect HTTP tra…   19                   [OK]
centos/nginx-112-centos7          Platform for running nginx 1.12 or building …   15                   
centos/nginx-18-centos7           Platform for running nginx 1.8 or building n…   13                   
raulr/nginx-wordpress             Nginx front-end for the official wordpress:f…   13                   [OK]
flashspys/nginx-static            Super Lightweight Nginx Image                   11                   [OK]
mailu/nginx                       Mailu nginx frontend                            9                    [OK]
sophos/nginx-vts-exporter         Simple server that scrapes Nginx vts stats a…   7                    [OK]
ansibleplaybookbundle/nginx-apb   An APB to deploy NGINX                          2                    [OK]
wodby/nginx                       Generic nginx                                   1                    [OK]

三 下载镜像

root@ubuntu:~# docker pull 仓库服务器:端口/项目名称/镜像名称:tag
root@ubuntu:~# docker pull nginx

四 查看本地镜像

root@ubuntu:~# docker images
REPOSITORY    TAG       IMAGE ID       CREATED       SIZE
nginx         latest    87a94228f133   2 weeks ago   133MB
hello-world   latest    feb5d9fea6a5   5 weeks ago   13.3kB

五 镜像导出

root@ubuntu:~# docker save nginx -o /opt/nginx.tar.gz
root@ubuntu:~# ls -l /opt/nginx.tar.gz 
-rw------- 1 root root 137544192 Oct 29 17:48 /opt/nginx.tar.gz

六 镜像导入

root@ubuntu:~# docker load < /opt/nginx.tar.gz 
e81bff2725db: Loading layer [==================================================>]  72.52MB/72.52MB
43f4e41372e4: Loading layer [==================================================>]  64.97MB/64.97MB
788e89a4d186: Loading layer [==================================================>]  3.072kB/3.072kB
f8e880dfc4ef: Loading layer [==================================================>]  4.096kB/4.096kB
f7e00b807643: Loading layer [==================================================>]  3.584kB/3.584kB
9959a332cf6e: Loading layer [==================================================>]  7.168kB/7.168kB
Loaded image: nginx:latest

七 镜像重命名

root@ubuntu:~# docker tag nginx test_nginx:v1.0
root@ubuntu:~# docker images
REPOSITORY    TAG       IMAGE ID       CREATED       SIZE
nginx         latest    87a94228f133   2 weeks ago   133MB
test_nginx    v1.0      87a94228f133   2 weeks ago   133MB
hello-world   latest    feb5d9fea6a5   5 weeks ago   13.3kB

八 查看镜像分层历史

点击查看代码
root@ubuntu:~# docker image history nginx
IMAGE          CREATED       CREATED BY                                      SIZE      COMMENT
87a94228f133   2 weeks ago   /bin/sh -c #(nop)  CMD ["nginx" "-g" "daemon…   0B        
<missing>      2 weeks ago   /bin/sh -c #(nop)  STOPSIGNAL SIGQUIT           0B        
<missing>      2 weeks ago   /bin/sh -c #(nop)  EXPOSE 80                    0B        
<missing>      2 weeks ago   /bin/sh -c #(nop)  ENTRYPOINT ["/docker-entr…   0B        
<missing>      2 weeks ago   /bin/sh -c #(nop) COPY file:09a214a3e07c919a…   4.61kB    
<missing>      2 weeks ago   /bin/sh -c #(nop) COPY file:0fd5fca330dcd6a7…   1.04kB    
<missing>      2 weeks ago   /bin/sh -c #(nop) COPY file:0b866ff3fc1ef5b0…   1.96kB    
<missing>      2 weeks ago   /bin/sh -c #(nop) COPY file:65504f71f5855ca0…   1.2kB     
<missing>      2 weeks ago   /bin/sh -c set -x     && addgroup --system -…   64MB      
<missing>      2 weeks ago   /bin/sh -c #(nop)  ENV PKG_RELEASE=1~buster     0B        
<missing>      2 weeks ago   /bin/sh -c #(nop)  ENV NJS_VERSION=0.6.2        0B        
<missing>      2 weeks ago   /bin/sh -c #(nop)  ENV NGINX_VERSION=1.21.3     0B        
<missing>      2 weeks ago   /bin/sh -c #(nop)  LABEL maintainer=NGINX Do…   0B        
<missing>      2 weeks ago   /bin/sh -c #(nop)  CMD ["bash"]                 0B        
<missing>      2 weeks ago   /bin/sh -c #(nop) ADD file:910392427fdf089bc…   69.3MB  

九 查看镜像信息

点击查看代码
root@ubuntu:~# docker inspect nginx
[
    {
        "Id": "sha256:87a94228f133e2da99cb16d653cd1373c5b4e8689956386c1c12b60a20421a02",
        "RepoTags": [
            "nginx:latest",
            "test_nginx:v1.0"
        ],
        "RepoDigests": [],
        "Parent": "",
        "Comment": "",
        "Created": "2021-10-12T02:03:40.360294686Z",
        "Container": "21fd1c6cb532225ca7e04c77f6592e220574b919aec07021663576ef438e0fee",
        "ContainerConfig": {
            "Hostname": "21fd1c6cb532",
            "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.21.3",
                "NJS_VERSION=0.6.2",
                "PKG_RELEASE=1~buster"
            ],
            "Cmd": [
                "/bin/sh",
                "-c",
                "#(nop) ",
                "CMD [\"nginx\" \"-g\" \"daemon off;\"]"
            ],
            "Image": "sha256:e30f1b92b2c67fbe72fb24af7353a945f6df4f48d9064d47bf0f51674311251e",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": [
                "/docker-entrypoint.sh"
            ],
            "OnBuild": null,
            "Labels": {
                "maintainer": "NGINX Docker Maintainers <docker-maint@nginx.com>"
            },
            "StopSignal": "SIGQUIT"
        },
        "DockerVersion": "20.10.7",
        "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.21.3",
                "NJS_VERSION=0.6.2",
                "PKG_RELEASE=1~buster"
            ],
            "Cmd": [
                "nginx",
                "-g",
                "daemon off;"
            ],
            "Image": "sha256:e30f1b92b2c67fbe72fb24af7353a945f6df4f48d9064d47bf0f51674311251e",
            "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": 133277153,
        "VirtualSize": 133277153,
        "GraphDriver": {
            "Data": {
                "LowerDir": "/var/lib/docker/overlay2/5936365e35391fb0cbd58837deca3071b3e184f4b379ea9083fbe92abb41d1a1/diff:/var/lib/docker/overlay2/283e87848d1aa658db2042ef4a4e5e647df5802730c329055a2a9125a9af6048/diff:/var/lib/docker/overlay2/cc6da890b6136654f4d247b48a783d065bbed8c0bcf36515ab7fbd15273280c1/diff:/var/lib/docker/overlay2/fe9766053b8733da341d4c5d868f7ea156025820b62d1028174902f3d5696168/diff:/var/lib/docker/overlay2/ade8e887e82afa5c813e45352bec310a0120dc546ea7039b226c2d3877216207/diff",
                "MergedDir": "/var/lib/docker/overlay2/272f7a79a4072689772c4344bc17bd165c91922aaa3bfc259a3411e87ba25499/merged",
                "UpperDir": "/var/lib/docker/overlay2/272f7a79a4072689772c4344bc17bd165c91922aaa3bfc259a3411e87ba25499/diff",
                "WorkDir": "/var/lib/docker/overlay2/272f7a79a4072689772c4344bc17bd165c91922aaa3bfc259a3411e87ba25499/work"
            },
            "Name": "overlay2"
        },
        "RootFS": {
            "Type": "layers",
            "Layers": [
                "sha256:e81bff2725dbc0bf2003db10272fef362e882eb96353055778a66cda430cf81b",
                "sha256:43f4e41372e42dd32309f6a7bdce03cf2d65b3ca34b1036be946d53c35b503ab",
                "sha256:788e89a4d186f3614bfa74254524bc2e2c6de103698aeb1cb044f8e8339a90bd",
                "sha256:f8e880dfc4ef19e78853c3f132166a4760a220c5ad15b9ee03b22da9c490ae3b",
                "sha256:f7e00b807643e512b85ef8c9f5244667c337c314fa29572206c1b0f3ae7bf122",
                "sha256:9959a332cf6e41253a9cd0c715fa74b01db1621b4d16f98f4155a2ed5365da4a"
            ]
        },
        "Metadata": {
            "LastTagTime": "2021-10-29T17:54:04.494435623+08:00"
        }
    }
]

十 删除镜像

点击查看代码
root@ubuntu:~# docker rmi nginx
Untagged: nginx:latest
Untagged: nginx@sha256:644a70516a26004c97d0d85c7fe1d0c3a67ea8ab7ddf4aff193d9f301670cf36
Deleted: sha256:87a94228f133e2da99cb16d653cd1373c5b4e8689956386c1c12b60a20421a02
Deleted: sha256:55b6972054b24c53054322a52748324df5797eefbb6dc374e41522a91d532dd5
Deleted: sha256:6b88aa6f4485486bfc779cccfbe4a7a47a502a7cff2cd70be89c59dcd0db12a8
Deleted: sha256:472c64059965c7b6b1b534ba07374c1d034b17c99acb3cf4534fe78abed41101
Deleted: sha256:788a5cf1e4599312b5923694f53e556ba0e2eb4a6bbb51958e0ec2b510345a49
Deleted: sha256:410f31f9ae37c62af85e8f9575c5f4d75542be1739ac1ca5982cf461be0b13bc
Deleted: sha256:e81bff2725dbc0bf2003db10272fef362e882eb96353055778a66cda430cf81b

root@ubuntu:~# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 87a94228f133 2 weeks ago 133MB
hello-world latest feb5d9fea6a5 5 weeks ago 13.3kB

标签:bin,docker,ago,nginx,sh,镜像,Docker,weeks
来源: https://www.cnblogs.com/wangguishe/p/15481669.html