1. 程式人生 > >docker 實踐(二)映象

docker 實踐(二)映象

一、獲取映象

1.1.從倉庫(Docker hub)獲取一個映象

# docker pull busybox
Using default tag: latest   #預設標籤為最新
latest: Pulling from library/busybox  #映象來源 
90e01955edcd: Pull complete          #pull 進度
Digest: sha256:2a03a6059f21e150ae84b0973863609494aad70f0a80eaeb64bddd8d92465812  #簽名
Status: Downloaded newer image for busybox:latest   #pull 狀態

1.2.檢視本地映象

# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
busybox             latest              59788edf1f3e        2 months ago        1.15MB

REPOSITORY:倉庫

TAG:映象標籤

IMAGE ID:映象唯一ID

CREATED:建立時間

SIZE:映象大小

二、映象管理

2.1.下載nginx映象

# docker pull nginx

2.1.2.檢視當前映象

# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
nginx               latest              568c4670fa80        2 weeks ago         109MB
busybox             latest              59788edf1f3e        2 months ago        1.15MB

2.2.為靜態打標籤

2.2.1.為nginx映象打一個tag

# docker tag nginx:latest nginx:1.2

注意:給映象打tag的時候不要只打"latest"

檢視本地映象:

# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
nginx               1.2                 568c4670fa80        2 weeks ago         109MB
nginx               latest              568c4670fa80        2 weeks ago         109MB
busybox             latest              59788edf1f3e        2 months ago        1.15MB

2.3.檢視映象詳細資訊

# docker inspect 568c4670fa80
[
    {
        "Id": "sha256:568c4670fa800978e08e4a51132b995a54f8d5ae83ca133ef5546d092b864acf",
        "RepoTags": [
            "nginx:1.2",
            "nginx:latest"
        ],
        "RepoDigests": [
            "[email protected]:5d32f60db294b5deb55d078cd4feb410ad88e6fe77500c87d3970eca97f54dba"
        ],
        "Parent": "",
        "Comment": "",
        "Created": "2018-11-27T22:21:45.207738888Z",
        "Container": "1455cab9c97f6945336dd97d5dfca0429eacbb739fcd362cc528ed8a175fcc7b",
        "ContainerConfig": {
            "Hostname": "1455cab9c97f",
            "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.15.7-1~stretch",
                "NJS_VERSION=1.15.7.0.2.6-1~stretch"
            ],
            "Cmd": [
                "/bin/sh",
                "-c",
                "#(nop) ",
                "CMD [\"nginx\" \"-g\" \"daemon off;\"]"
            ],
            "ArgsEscaped": true,
            "Image": "sha256:cf9409661039371fa3448619fb988625e4542108921c4c8f923c5bccc51601eb",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": [],
            "Labels": {
                "maintainer": "NGINX Docker Maintainers <[email protected]>"
            },
            "StopSignal": "SIGTERM"
        },
        "DockerVersion": "17.06.2-ce",
        "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.15.7-1~stretch",
                "NJS_VERSION=1.15.7.0.2.6-1~stretch"
            ],
            "Cmd": [
                "nginx",
                "-g",
                "daemon off;"
            ],
            "ArgsEscaped": true,
            "Image": "sha256:cf9409661039371fa3448619fb988625e4542108921c4c8f923c5bccc51601eb",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": [],
            "Labels": {
                "maintainer": "NGINX Docker Maintainers <[email protected]>"
            },
            "StopSignal": "SIGTERM"
        },
        "Architecture": "amd64",
        "Os": "linux",
        "Size": 109116878,
        "VirtualSize": 109116878,
        "GraphDriver": {
            "Data": {
                "LowerDir": "/var/lib/docker/overlay2/a636ad849dde56a8f7564fd10fdc1295f8147a2c69415c813397005e36912eb8/diff:/var/lib/docker/overlay2/e7600dc218916e990c0a8da2e5ef0b704a3fbde3fadc974c0c6bfbfb59bdbfdd/diff",
                "MergedDir": "/var/lib/docker/overlay2/dc899d7a73b75da0dbfbd23f7f46588b3973fed065517f14705145643ab0b735/merged",
                "UpperDir": "/var/lib/docker/overlay2/dc899d7a73b75da0dbfbd23f7f46588b3973fed065517f14705145643ab0b735/diff",
                "WorkDir": "/var/lib/docker/overlay2/dc899d7a73b75da0dbfbd23f7f46588b3973fed065517f14705145643ab0b735/work"
            },
            "Name": "overlay2"
        },
        "RootFS": {
            "Type": "layers",
            "Layers": [
                "sha256:ef68f6734aa485edf13a8509fe60e4272428deaf63f446a441b79d47fc5d17d3",
                "sha256:ad5345cbb119f7c720123e3adf28b164143e4157ca6e46a629ca694e75f7825f",
                "sha256:ece4f9fdef598687f23d39643bacbf2c609201b087b93bbae81b931da72d2a64"
            ]
        },
        "Metadata": {
            "LastTagTime": "2018-12-13T20:44:49.706590964-05:00"
        }
    }
]

2.4.查詢映象

# docker search php
NAME                                                      DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
php                                                       While designed for web development, the PHP …   4183                [OK]                
phpmyadmin/phpmyadmin                                     A web interface for MySQL and MariaDB.          689                                     [OK]
richarvey/nginx-php-fpm                                   Container running Nginx + PHP-FPM capable of…   663                                     [OK]
composer                                                  Composer is a dependency manager written in …   325                 [OK]                
adminer                                                   Database management in a single PHP file.       196                 [OK]                
php-zendserver                                            Zend Server - the integrated PHP application…   160                 [OK]                
webdevops/php-nginx                                       Nginx with PHP-FPM                              119                                     [OK]
webdevops/php-apache-dev                                  PHP with Apache for Development (eg. with xd…   94                                      [OK]
webdevops/php-apache                                      Apache with PHP-FPM (based on webdevops/php)    80                                      [OK]
phpunit/phpunit                                           PHPUnit is a programmer-oriented testing fra…   65                                      [OK]
bitnami/php-fpm                                           Bitnami PHP-FPM Docker Image                    62                                      [OK]
nazarpc/phpmyadmin                                        phpMyAdmin as Docker container, based on off…   60                                      [OK]
1and1internet/ubuntu-16-nginx-php-phpmyadmin-mysql-5      ubuntu-16-nginx-php-phpmyadmin-mysql-5          48                                      [OK]
tetraweb/php                                              PHP 5.5, 5.6, 7.0, 7.1 for CI and running te…   30                                      [OK]
wodby/drupal-php                                          PHP for Drupal                                  27                                      [OK]
circleci/php                                              CircleCI images for PHP                         21                                      
clinta/phpipam                                            phpIPAM web IP address management applicatio…   18                                      [OK]
centos/php-56-centos7                                     Platform for building and running PHP 5.6 ap…   17                                      
antage/apache2-php5                                       Docker image for running Apache 2.x with PHP…   12                                      [OK]
graze/php-alpine                                          Smallish php7 alpine image with some common …   11                                      [OK]
1and1internet/ubuntu-16-nginx-php-phpmyadmin-mariadb-10   ubuntu-16-nginx-php-phpmyadmin-mariadb-10       11                                      [OK]
appsvc/php                                                Azure App Service php dockerfiles               6                                       [OK]
phpspec/phpspec                                           PHPSpec: A php toolset to drive emergent des…   5                                       [OK]
lephare/php                                               PHP container                                   4                                       [OK]
isotopab/php                                              Docker PHP                                      0                                       [OK]

NAME:映象名稱

DESCRIPTION:映象描述

STARS:使用者對映象的評分

OFFICIAL:是否為官方映象。

AUTOMATED:是否使用了自動構建


2.5.刪除映象

docker rmi [NAME]/[CONTAINER ID]對於不需要的映象,可以使用rmi命令刪除。

-f:強制刪除


2.5.1.刪除自己tag的nginx

# docker rmi nginx:1.2
Untagged: nginx:1.2
# docker images       
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
nginx               latest              568c4670fa80        2 weeks ago         109MB
busybox             latest              59788edf1f3e        2 months ago        1.15MB

2.5.2.下載的nginx還在,還可以使用ID刪除

# docker rmi 568c4670fa80
Untagged: nginx:latest
Untagged: [email protected]:5d32f60db294b5deb55d078cd4feb410ad88e6fe77500c87d3970eca97f54dba
Deleted: sha256:568c4670fa800978e08e4a51132b995a54f8d5ae83ca133ef5546d092b864acf
Deleted: sha256:ac0442c0fafd48e24a96fa3099ea7ad20012c8759e1dd03dd387dbfbe382984c
Deleted: sha256:6b9d35d8d75115937cd78da275f527cccef672cbd71f34062dffe2e930fd7e13
Deleted: sha256:ef68f6734aa485edf13a8509fe60e4272428deaf63f446a441b79d47fc5d17d3
# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
busybox             latest              59788edf1f3e        2 months ago        1.15MB

2.5.3.刪除全部映象:

# docker rmi $(docker images -q)