zoukankan      html  css  js  c++  java
  • Docker 镜像管理

      镜像是什么

      镜像从哪里来

      镜像和容器的关系

      存储驱动

      镜像管理命令

    什么是镜像:

      简单说,Docker镜像是一个不包含Linux内核而且又精简的Linux操作系统(内核是共享宿主机的)

    镜像从哪里来?

      Docker Hub 是由Docker公司负责维护的公共注册中心,包含大量的容器镜像,Docker工具默认从这个镜像来下载镜像 https://hub.docker.com/explore,

      这个是国外的镜像源,所以下载会很慢,有时候还会被墙,所以我们换成国内的镜像

    vim /etc/docker/daemon.json

    添加内容:

    {
    "registry-mirrors":["https://registry.docker-cn.com"]
    }

    systemctl restart docker    重启docker

    docker  images 查看我们下载的镜像有哪些

    docker pull nginx:1.12  安装nginx镜像(不指定版本号的话,默认版本latest)

    镜像和容器的关系:

    镜像不是一个单一的文件,而是有多层构成,我们可以通过docker history <ID/NAME>查看镜像中各层内容及大小,每层对应着Dockerfile中的一条指令,Docker镜像默认存储在/var/lib/docker/<storge-driver>中

    容器其实是在镜像的最上层加了一层读写层,在运行容器里做的任何文件改动,都会写到这个读写层,如果容器删除了,嘴上面的读写层也就删除了。改动也就丢失了。

    Docker 使用存储驱动管理镜像每层内容以及可读写层的容器层

    docker history haproxy:1.7 命令我们可以看到镜像内部执行的history命令

    存储驱动:(Docker 在管理驱动的时候都是通过这个驱动去管理容器的)

    aufs Ubuntu

    devicemapper  centos

    overlay  只支持ext4,xfs文件系统

    overlay2(性能比overlay好),只支持ext4,xfs文件系统

    Docker管理指令:

      Management  Commands:
      config      Manage Docker configs
      container   Manage containers
      image       Manage images
      network     Manage networks
      node        Manage Swarm nodes
      plugin      Manage plugins
      secret      Manage Docker secrets
      service     Manage services
      swarm       Manage Swarm
      system      Manage Docker
      trust       Manage trust on Docker images
      volume      Manage volumes

    Docker image 指令:

    [root@node02 ~]# docker image --help
    
    Usage:	docker image COMMAND
    
    Manage images
    
    Options:
    
    Commands:
      build       Build an image from a Dockerfile
      history     Show the history of an image
      import      Import the contents from a tarball to create a filesystem image
      inspect     Display detailed information on one or more images
      load        Load an image from a tar archive or STDIN
      ls          List images
      prune       Remove unused images
      pull        Pull an image or a repository from a registry
      push        Push an image or a repository to a registry(推送到自己的私有仓库)
      rm          Remove one or more images
      save        Save one or more images to a tar archive (streamed to STDOUT by default)
      tag         Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
    
    Run 'docker image COMMAND --help' for more information on a command.
    

     

    [root@node02 ~]# docker tag nginx:1.7.9 nginx:v1.7.9   给nginx:1.7.9 打一个tag v1.7.9
    [root@node02 ~]# docker images | grep nginx
    nginx                                                    latest              ae513a47849c        4 months ago        109MB
    nginx                                                    1.7.9               84581e99d807        3 years ago         91.6MB
    nginx                                                    v1.7.9              84581e99d807        3 years ago         91.6MB

    [root@node02 ~]# docker image save nginx:1.7.9 >nginx.1.7.9.tar

    [root@node02 ~]# docker load < nginx.1.7.9.tar
    Loaded image: nginx:1.7.9

      

    指令 描述
    ls 列出镜像
    build 构建镜像来自Dockerfile
    history 查看镜像历史
    inspect 显示一个或多个镜像详细信息
    pull 从镜像仓库拉取镜像
    push 推送一个镜像到镜像仓库
    rm 移除一个或多个镜像
    prune 移除未使用的镜像。没有被标记或被任何容器引用的。
    tag 创建一个引用源镜像标记目标镜像
    export 导出容器文件系统到tar归档文件
    import 导入容器文件系统tar归档文件创建镜像
    save 保存一个或多个镜像到一个tar归档文件
    load 加载镜像来自tar归档或标准输入


  • 相关阅读:
    制作计算器的代码(C#)
    Oracle如何实现创建数据库、备份数据库及数据导出导入操作
    XmlDocument类
    Android强大的开源库与系统架构工具
    IO
    胎压监测设备
    福施福、爱乐维、玛特纳各成分比较(已换算成同一单位)
    用车不容忽视的细节
    汽车必备车饰和常用物品
    j2ee指导型框架或示例
  • 原文地址:https://www.cnblogs.com/smail-bao/p/9607900.html
Copyright © 2011-2022 走看看