我爱小虾 发表于 2019-2-20 09:26:20

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": [
            "nginx@sha256: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 "
            },
            "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 "
            },
            "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                               
phpmyadmin/phpmyadmin                                     A web interface for MySQL and MariaDB.          689                                    
richarvey/nginx-php-fpm                                 Container running Nginx + PHP-FPM capable of…   663                                    
composer                                                Composer is a dependency manager written in …   325                              
adminer                                                   Database management in a single PHP file.       196                              
php-zendserver                                          Zend Server - the integrated PHP application…   160                              
webdevops/php-nginx                                       Nginx with PHP-FPM                              119                                    
webdevops/php-apache-dev                                  PHP with Apache for Development (eg. with xd…   94                                    
webdevops/php-apache                                    Apache with PHP-FPM (based on webdevops/php)    80                                    
phpunit/phpunit                                           PHPUnit is a programmer-oriented testing fra…   65                                    
bitnami/php-fpm                                           Bitnami PHP-FPM Docker Image                  62                                    
nazarpc/phpmyadmin                                        phpMyAdmin as Docker container, based on off…   60                                    
1and1internet/ubuntu-16-nginx-php-phpmyadmin-mysql-5      ubuntu-16-nginx-php-phpmyadmin-mysql-5          48                                    
tetraweb/php                                              PHP 5.5, 5.6, 7.0, 7.1 for CI and running te…   30                                    
wodby/drupal-php                                          PHP for Drupal                                  27                                    
circleci/php                                              CircleCI images for PHP                         21                                    
clinta/phpipam                                          phpIPAM web IP address management applicatio…   18                                    
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                                    
graze/php-alpine                                          Smallish php7 alpine image with some common …   11                                    
1and1internet/ubuntu-16-nginx-php-phpmyadmin-mariadb-10   ubuntu-16-nginx-php-phpmyadmin-mariadb-10       11                                    
appsvc/php                                                Azure App Service php dockerfiles               6                                       
phpspec/phpspec                                           PHPSpec: A php toolset to drive emergent des…   5                                       
lephare/php                                             PHP container                                 4                                       
isotopab/php                                              Docker PHP                                    0                                         NAME:镜像名称
  DESCRIPTION:镜像描述
  STARS:用户对镜像的评分
  OFFICIAL:是否为官方镜像。
  AUTOMATED:是否使用了自动构建
  2.5.删除镜像
  docker rmi /对于不需要的镜像,可以使用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: nginx@sha256: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)


页: [1]
查看完整版本: docker 实践(二)镜像